Επεξεργασία

Κοινή χρήση μέσω


TcpClient.Client Property

Definition

Gets or sets the underlying Socket.

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

Property Value

The underlying network Socket.

Examples

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)
{
    s.SetSocketOption(SocketOptionLevel.Socket, 
                 SocketOptionName.ReceiveBuffer, 16384);
    Console.WriteLine(
        "client is not connected, ReceiveBuffer set\n");
}
else
{
    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)
Else
   Console.WriteLine("client is connected")
End If

Remarks

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