Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Net.​Sockets.​TcpClient
Assembly: System.Net.Sockets
Inheritance: object → TcpClient
Implemented Interfaces
Provides client connections for TCP network services.
Properties
protected
bool
Active
Gets or sets a value that indicates whether a connection has been made.
public
int
Available
Gets the amount of data that has been received from the network and is available to be read.
public
Socket
Client
Gets or sets the underlying <see cref="T:System.Net.Sockets.Socket" /> .
public
bool
Connected
Gets a value indicating whether the underlying <see cref="T:System.Net.Sockets.Socket" /> for a <see cref="T:System.Net.Sockets.TcpClient" /> is connected to a remote host.
public
bool
ExclusiveAddressUse
Gets or sets a <see cref="T:System.Boolean" /> value that specifies whether the <see cref="T:System.Net.Sockets.TcpClient" /> allows only one client to use a port.
public
LingerOption
LingerState
Gets or sets information about the linger state of the associated socket.
public
bool
NoDelay
Gets or sets a value that disables a delay when send or receive buffers are not full.
public
int
ReceiveBufferSize
Gets or sets the size of the receive buffer.
public
int
ReceiveTimeout
Gets or sets the amount of time a <see cref="T:System.Net.Sockets.TcpClient" /> will wait to receive data once a read operation is initiated.
public
int
SendBufferSize
Gets or sets the size of the send buffer.
public
int
SendTimeout
Gets or sets the amount of time a <see cref="T:System.Net.Sockets.TcpClient" /> will wait for a send operation to complete successfully.
Methods
public
IAsyncResult
BeginConnect​(IPAddress address,
int port,
AsyncCallback? requestCallback,
object state)
Begins an asynchronous request for a remote host connection. The remote host is specified by an <see cref="T:System.Net.IPAddress" /> and a port number ( <see cref="T:System.Int32" /> ).
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous connection.
address
The <see cref="T:System.Net.IPAddress" /> of the remote host.
port
The port number of the remote host.
requestCallback
An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state
A user-defined object that contains information about the connect operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public
IAsyncResult
BeginConnect​(IPAddress[] addresses,
int port,
AsyncCallback? requestCallback,
object state)
Begins an asynchronous request for a remote host connection. The remote host is specified by an <see cref="T:System.Net.IPAddress" /> array and a port number ( <see cref="T:System.Int32" /> ).
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous connection.
addresses
At least one <see cref="T:System.Net.IPAddress" /> that designates the remote hosts.
port
The port number of the remote hosts.
requestCallback
An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state
A user-defined object that contains information about the connect operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public
IAsyncResult
BeginConnect​(string host,
int port,
AsyncCallback? requestCallback,
object state)
Begins an asynchronous request for a remote host connection. The remote host is specified by a host name ( <see cref="T:System.String" /> ) and a port number ( <see cref="T:System.Int32" /> ).
Returns An <see cref="T:System.IAsyncResult" /> object that references the asynchronous connection.
host
The name of the remote host.
port
The port number of the remote host.
requestCallback
An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete.
state
A user-defined object that contains information about the connect operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.
public
void
Close​()
Disposes this <see cref="T:System.Net.Sockets.TcpClient" /> instance and requests that the underlying TCP connection be closed.
public
void
Connect​(IPAddress address,
int port)
Connects the client to a remote TCP host using the specified IP address and port number.
address
The <see cref="T:System.Net.IPAddress" /> of the host to which you intend to connect.
port
The port number to which you intend to connect.
public
void
Connect​(IPAddress[] ipAddresses,
int port)
Connects the client to a remote TCP host using the specified IP addresses and port number.
ipAddresses
The <see cref="T:System.Net.IPAddress" /> array of the host to which you intend to connect.
port
The port number to which you intend to connect.
public
void
Connect​(IPEndPoint remoteEP)
Connects the client to a remote TCP host using the specified remote network endpoint.
remoteEP
The <see cref="T:System.Net.IPEndPoint" /> to which you intend to connect.
public
void
Connect​(string hostname,
int port)
Connects the client to the specified port on the specified host.
hostname
The DNS name of the remote host to which you intend to connect.
port
The port number of the remote host to which you intend to connect.
ConnectAsync​(IPAddress address,
int port)
Connects the client to a remote TCP host using the specified IP address and port number as an asynchronous operation.
Returns The task object representing the asynchronous operation.
address
The <see cref="T:System.Net.IPAddress" /> of the host to which you intend to connect.
port
The port number to which you intend to connect.
ConnectAsync​(IPAddress address,
int port,
Threading.​CancellationToken cancellationToken)
Connects the client to a remote TCP host using the specified IP address and port number as an asynchronous operation.
Returns A task that represents the asynchronous connection operation.
address
The IP address of the remote host.
port
The port number of the remote host.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
ConnectAsync​(IPAddress[] addresses,
int port)
Connects the client to a remote TCP host using the specified IP addresses and port number as an asynchronous operation.
Returns The task object representing the asynchronous operation.
addresses
The <see cref="T:System.Net.IPAddress" /> array of the host to which you intend to connect.
port
The port number to which you intend to connect.
ConnectAsync​(IPAddress[] addresses,
int port,
Threading.​CancellationToken cancellationToken)
Connects the client to a remote TCP host using the specified IP addresses and port number as an asynchronous operation.
Returns A task that represents the asynchronous connection operation.
addresses
The array of IP address of the remote host.
port
The port number of the remote host.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
ConnectAsync​(IPEndPoint remoteEP)
Connects the client to a remote TCP host using the specified endpoint as an asynchronous operation.
Returns A task representing the asynchronous operation.
remoteEP
The <see cref="T:System.Net.IPEndPoint" /> to which you intend to connect.
ConnectAsync​(IPEndPoint remoteEP,
Threading.​CancellationToken cancellationToken)
Connects the client to a remote TCP host using the specified endpoint as an asynchronous operation.
Returns A task representing the asynchronous operation.
remoteEP
The <see cref="T:System.Net.IPEndPoint" /> to which you intend to connect.
cancellationToken
A cancellation token used to propagate notification that this operation should be canceled.
ConnectAsync​(string host,
int port)
Connects the client to the specified TCP port on the specified host as an asynchronous operation.
Returns The task object representing the asynchronous operation.
host
The DNS name of the remote host to which you intend to connect.
port
The port number of the remote host to which you intend to connect.
ConnectAsync​(string host,
int port,
Threading.​CancellationToken cancellationToken)
Connects the client to the specified TCP port on the specified host as an asynchronous operation.
Returns A task that represents the asynchronous connection operation.
host
The DNS name of the remote host.
port
The port number of the remote host.
cancellationToken
A cancellation token that can be used to signal the asynchronous operation should be canceled.
public
void
Dispose​()
Releases the managed and unmanaged resources used by the <see cref="T:System.Net.Sockets.TcpClient" /> .
protected
void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Net.Sockets.TcpClient" /> and optionally releases the managed resources.
disposing
Set to <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public
void
EndConnect​(IAsyncResult asyncResult)
Ends a pending asynchronous connection attempt.
asyncResult
An <see cref="T:System.IAsyncResult" /> object returned by a call to <see cref="Overload:System.Net.Sockets.TcpClient.BeginConnect" /> .
protected
void
Finalize​()
Frees resources used by the <see cref="T:System.Net.Sockets.TcpClient" /> class.
public
NetworkStream
GetStream​()
Returns the <see cref="T:System.Net.Sockets.NetworkStream" /> used to send and receive data.
Returns The underlying <see cref="T:System.Net.Sockets.NetworkStream" /> .
public
bool
Equals​(object obj)
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object