Accepts a pending connection request.
Assembly: System (in System.dll)
is a blocking method that returns a Socket that you can use to send and receive data. If you want to avoid blocking, use the Pending method to determine if connection requests are available in the incoming connection queue.
The Socket returned is initialized with the IP address and port number of the remote host. You can use any of the Send and Receive methods available in the Socket class to communicate with the remote host. When you are finished using the Socket, be sure to call its Close method. If your application is relatively simple, consider using the AcceptTcpClient method rather than the method. TcpClient provides you with simple methods for sending and receiving data over a network in blocking synchronous mode.
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.
// Accepts the pending client connection and returns a socket for communciation. Socket socket = tcpListener.AcceptSocket(); Console.WriteLine("Connection accepted."); string responseString = "You have successfully connected to me"; //Forms and sends a response string to the connected client. Byte sendBytes = Encoding.ASCII.GetBytes(responseString); int i = socket.Send(sendBytes); Console.WriteLine("Message Sent /> : " + responseString);
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.