O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

TcpClient

Synopsis

This class provides a client-side abstraction of the sockets API. The zero-argument form of the constructor creates the client. Connect to a remote server with the Connect() method (you must specify an existing System.Net.IPEndPoint or a remote IP address and port number). Alternatively, use an overloaded form of the constructor to simultaneously create the client and make the connection.

This class completely obscures the underlying socket. However, the GetStream() method returns a NetworkStream that you can use to send and receive data across the network.

public class TcpClient : IDisposable {
// Public Constructors
   public method TcpClient();  
   public method TcpClient(System.Net.IPEndPoint localEP);  
   public method TcpClient(string hostname, int port);  
// Public Instance Properties
   public field LingerOption LingerState{set; get; } 
   public field bool NoDelay{set; get; } 
   public field int ReceiveBufferSize{set; get; } 
   public field int ReceiveTimeout{set; get; } 
   public field int SendBufferSize{set; get; } 
   public field int SendTimeout{set; get; } 
// Protected Instance Properties
   protected field bool Active{set; get; } 
   protected field Socket Client{set; get; } 
// Public Instance Methods
   public method void Close();  
   public method void Connect(System.Net.IPAddress address, 
        int port);  
   public method void Connect(
        System.Net.IPEndPoint remoteEP);  
   public method void Connect(string hostname, int port);  
   public method NetworkStream GetStream();  
// Protected Instance Methods ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required