TcpClient.Client Property


Gets or sets the underlying Socket.

 property System::Net::Sockets::Socket ^ Client { System::Net::Sockets::Socket ^ get(); void set(System::Net::Sockets::Socket ^ value); };
protected System.Net.Sockets.Socket Client { get; set; }
member this.Client : System.Net.Sockets.Socket with get, set
Protected Property Client As Socket

Property Value

The underlying network Socket.


The following code example demonstrates the use of the Client property. In this example, the receive buffer size of the underlying Socket is changed.

TcpClient client = new TcpClient();
Socket s = client.Client;

if (!s.Connected)
                 SocketOptionName.ReceiveBuffer, 16384);
        "client is not connected, ReceiveBuffer set\n");
    Console.WriteLine("client is connected");
Dim client As New TcpClient()
Dim s As Socket = client.Client

If Not s.Connected Then
   s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 16384)
   Console.WriteLine("client is not connected, ReceiveBuffer set" + ControlChars.Lf)
   Console.WriteLine("client is connected")
End If 


TcpClient creates a Socket to send and receive data over a network. Classes deriving from TcpClient can use this property to get or set this Socket. Use the underlying Socket returned from Client if you require access beyond that which TcpClient provides. You can also use Client to set the underlying Socket to an existing Socket. This might be useful if you want to take advantage of the simplicity of TcpClient using a pre-existing Socket.

Applies to

See also