Socket.Listen Method (Int32)
Places a Socket in a listening state.
Assembly: System (in System.dll)
Socket to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance. To determine the maximum number of connections you can specify, retrieve the MaxConnections value. does not block.causes a connection-oriented
If you receive a SocketException, use the ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error. Use Accept or BeginAccept to accept a connection from the queue.
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.
The backlog parameter is limited to different values depending on the Operating System. You may specify a higher value, but the backlog will be limited based on the Operating System.
The following code example uses Socket to listen for incoming connections.
// create the socket Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // bind the listening socket to the port IPAddress hostIP = (Dns.Resolve(IPAddress.Any.ToString())).AddressList; IPEndPoint ep = new IPEndPoint(hostIP, port); listenSocket.Bind(ep); // start listening listenSocket.Listen(backlog);
Available since 10
Available since 1.1
Windows Phone Silverlight
Available since 8.0