Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Developer's Guide 
TCP/UDP 

Applications can use Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) services with the TcpClient, TcpListener, and UdpClient classes. These protocol classes are built on top of the System.Net.Sockets.Socket 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 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 GetStream method to return the network stream, and then call the stream's Read and Write 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 Send method to send the data to the network and the Receive method to receive an incoming datagram.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker