Overview
The System.Net.Sockets.TcpClient
and System.Net.Sockets.TcpListener
classes provide a simple way to implement TCP network communication in .NET applications. They support both synchronous and asynchronous operations, IPv4/IPv6, and SSL/TLS encryption.
Classes
TcpClient | Provides client connections for TCP network services. |
TcpListener | Listens for incoming TCP connection requests. |
NetworkStream | Provides the underlying stream of data for TCP sockets. |
Common Methods
TcpClient.ConnectAsync(IPAddress, int)
– Asynchronously connects to a remote host.TcpListener.Start()
– Begins listening for incoming connections.TcpListener.AcceptTcpClientAsync()
– Accepts an incoming connection asynchronously.NetworkStream.ReadAsync(byte[], int, int)
– Reads data from the stream.NetworkStream.WriteAsync(byte[], int, int)
– Writes data to the stream.