MSDN says about the Socket.Listen
method:
Listen causes a... Socket to listen for incoming connection attempts. The backlog parameter specifies the number of incoming connections that can be queued for acceptance... Use Accept or BeginAccept to accept a connection from the queue.
This implies that the socket will put incoming connections into a queue. How do we determine the number of queued connections?
var localEndPoint = new IPEndPoint(IPAddress.Any, Port);
var serverSocket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
serverSocket.Bind(localEndPoint);
// listen for incoming connections; queue `socketBacklog` of them
// Listen bit.ly/21vz22b
serverSocket.Listen(socketBacklog);
// how do we do this?
serverSocket.CountQueuedConnections()
One thing I have tried, which clearly does not work, is serverSocket.Poll(timeToWait, SelectMode.SelectRead)
. This always returns false
.