TcpClient.Client 屬性

定義

取得或設定基礎 SocketGets or sets the underlying Socket.

protected:
 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

屬性值

基礎網路 SocketThe underlying network Socket.

範例

下列程式碼範例示範Client屬性的用法。The following code example demonstrates the use of the Client property. 在此範例中,會變更基礎Socket的接收緩衝區大小。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 

備註

TcpClient建立, Socket以透過網路傳送和接收資料。TcpClient creates a Socket to send and receive data over a network. 衍生自的TcpClient類別可以使用這個屬性來取得或設定Socket這個。Classes deriving from TcpClient can use this property to get or set this Socket. 如果您Socket 需要的Client存取超出提供的,請使用從傳回的基礎。TcpClientUse the underlying Socket returned from Client if you require access beyond that which TcpClient provides. 您也可以使用Client ,將基礎Socket設定為現有Socket的。You can also use Client to set the underlying Socket to an existing Socket. 如果您想要利用既有TcpClient Socket的簡單方法,這可能很有用。This might be useful if you want to take advantage of the simplicity of TcpClient using a pre-existing Socket.

適用於

另請參閱