| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.tgt_pltfrm | ms.topic | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
TCP-UDP |
03/30/2017 |
.net-framework |
article |
|
|
df29b4b0-49e8-4923-82b9-13150dfc40f5 |
8 |
mcleblanc |
markl |
markl |
TCP-UDP
Applications can use Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) services with the xref:System.Net.Sockets.TcpClient, xref:System.Net.Sockets.TcpListener, and xref:System.Net.Sockets.UdpClient classes. These protocol classes are built on top of the xref:System.Net.Sockets.Socket?displayProperty=nameWithType class and take care of the details of transferring data.
The protocol classes use the synchronous methods of the Socket class to provide simple and straightforward access to network services without the overhead of maintaining state information or knowing the details of setting up protocol-specific sockets. To use asynchronous Socket methods, you can use the asynchronous methods supplied by the xref:System.Net.Sockets.NetworkStream class. To access features of the Socket class not exposed by the protocol classes, you must use the Socket class.
TcpClient and TcpListener represent the network using the NetworkStream class. You use the xref:System.Net.Sockets.TcpClient.GetStream%2A method to return the network stream, and then call the stream's xref:System.Net.Sockets.NetworkStream.Read%2A and xref:System.Net.Sockets.NetworkStream.Write%2A methods. The NetworkStream does not own the protocol classes' underlying socket, so closing it does not affect the socket.
The UdpClient class uses an array of bytes to hold the UDP datagram. You use the xref:System.Net.Sockets.UdpClient.Send%2A method to send the data to the network and the xref:System.Net.Sockets.UdpClient.Receive%2A method to receive an incoming datagram.
See Also
Using TCP Services
Using UDP Services
Using Streams on the Network
Using an Asynchronous Server Socket
Using an Asynchronous Client Socket
Using Application Protocols