TcpClient Class

 

Provides client connections for TCP network services.

Namespace:   System.Net.Sockets
Assembly:  System (in System.dll)

System.Object
  System.Net.Sockets.TcpClient

type TcpClient = 
    class
        interface IDisposable
    end

NameDescription
System_CAPS_pubmethodTcpClient()

Initializes a new instance of the TcpClient class.

System_CAPS_pubmethodTcpClient(AddressFamily)

Initializes a new instance of the TcpClient class with the specified family.

System_CAPS_pubmethodTcpClient(IPEndPoint)

Initializes a new instance of the TcpClient class and binds it to the specified local endpoint.

System_CAPS_pubmethodTcpClient(String, Int32)

Initializes a new instance of the TcpClient class and connects to the specified port on the specified host.

NameDescription
System_CAPS_protpropertyActive

Gets or set a value that indicates whether a connection has been made.

System_CAPS_pubpropertyAvailable

Gets the amount of data that has been received from the network and is available to be read.

System_CAPS_pubpropertyClient

Gets or sets the underlying Socket.

System_CAPS_pubpropertyConnected

Gets a value indicating whether the underlying Socket for a TcpClient is connected to a remote host.

System_CAPS_pubpropertyExclusiveAddressUse

Gets or sets a Boolean value that specifies whether the TcpClient allows only one client to use a port.

System_CAPS_pubpropertyLingerState

Gets or sets information about the linger state of the associated socket.

System_CAPS_pubpropertyNoDelay

Gets or sets a value that disables a delay when send or receive buffers are not full.

System_CAPS_pubpropertyReceiveBufferSize

Gets or sets the size of the receive buffer.

System_CAPS_pubpropertyReceiveTimeout

Gets or sets the amount of time a TcpClient will wait to receive data once a read operation is initiated.

System_CAPS_pubpropertySendBufferSize

Gets or sets the size of the send buffer.

System_CAPS_pubpropertySendTimeout

Gets or sets the amount of time a TcpClient will wait for a send operation to complete successfully.

NameDescription
System_CAPS_pubmethodBeginConnect(IPAddress, Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The remote host is specified by an IPAddress and a port number (Int32).

System_CAPS_pubmethodBeginConnect(IPAddress[], Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The remote host is specified by an IPAddress array and a port number (Int32).

System_CAPS_pubmethodBeginConnect(String, Int32, AsyncCallback, Object)

Begins an asynchronous request for a remote host connection. The remote host is specified by a host name (String) and a port number (Int32).

System_CAPS_pubmethodClose()

Disposes this TcpClient instance and requests that the underlying TCP connection be closed.

System_CAPS_pubmethodConnect(IPAddress, Int32)

Connects the client to a remote TCP host using the specified IP address and port number.

System_CAPS_pubmethodConnect(IPAddress[], Int32)

Connects the client to a remote TCP host using the specified IP addresses and port number.

System_CAPS_pubmethodConnect(IPEndPoint)

Connects the client to a remote TCP host using the specified remote network endpoint.

System_CAPS_pubmethodConnect(String, Int32)

Connects the client to the specified port on the specified host.

System_CAPS_pubmethodConnectAsync(IPAddress, Int32)

Connects the client to a remote TCP host using the specified IP address and port number as an asynchronous operation.

System_CAPS_pubmethodConnectAsync(IPAddress[], Int32)

Connects the client to a remote TCP host using the specified IP addresses and port number as an asynchronous operation.

System_CAPS_pubmethodConnectAsync(String, Int32)

Connects the client to the specified TCP port on the specified host as an asynchronous operation.

System_CAPS_pubmethodDispose()

Releases the managed and unmanaged resources used by the TcpClient.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the TcpClient and optionally releases the managed resources.

System_CAPS_pubmethodEndConnect(IAsyncResult)

Ends a pending asynchronous connection attempt.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Frees resources used by the TcpClient class.(Overrides Object.Finalize().)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetStream()

Returns the NetworkStream used to send and receive data.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

The TcpClient class provides simple methods for connecting, sending, and receiving stream data over a network in synchronous blocking mode.

In order for TcpClient to connect and exchange data, a TcpListener or Socket created with the TCP ProtocolType must be listening for incoming connection requests. You can connect to this listener in one of the following two ways:

  • Create a TcpClient and call one of the three available Connect methods.

  • Create a TcpClient using the host name and port number of the remote host. This constructor will automatically attempt a connection.

System_CAPS_noteNote

If you want to send connectionless datagrams in synchronous blocking mode, use the UdpClient class.

Notes to Inheritors:

To send and receive data, use the GetStream method to obtain a NetworkStream. Call the Write and Read methods of the NetworkStream to send and receive data with the remote host. Use the Close method to release all resources associated with the TcpClient.

The following code example establishes a TcpClient connection.

No code example is currently available or this language may not be supported.

SocketPermission

Permission to establish an outgoing connection or accept an incoming request.

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: