Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine MaxConnections for Socket.Listen()?

Tags:

c#

.net

sockets

The System.Net.Sockets.Socket.Listen() function requires a backlog argument, which is the max number of connections that Listen() can queue up.

From the MSDN documentation:

To determine the maximum number of connections you can specify, retrieve the MaxConnections value.

So I click on MaxConnections and the link takes me to the page for SocketOptionName Enumeration, which says:

MaxConnections: Not supported; will throw a SocketException if used.

So the documentation for this MaxConnections enumeration says not to use it, but doesn't give an alternative. How do I determine the max connections, so that I have a value to pass into the Socket.Listen() function?

like image 887
paperduck Avatar asked May 02 '14 15:05

paperduck


People also ask

Which is the definition for the listen () function?

The listen() call indicates a readiness to accept client connection requests. It transforms an active socket into a passive socket. Once called, socket can never be used as an active socket to initiate connection requests. Calling listen() is the third of four steps that a server performs to accept a connection.

What is the order of arguments in listen ()?

The listen() function marks a connection-mode socket (for example, those of type SOCK_STREAM), specified by the socket argument s, as accepting connections, and limits the number of outstanding connections in the socket's listen queue to the value specified by the backlog argument.


1 Answers

Exception will be thrown when you will try to set socket option and use MaxConnections as an option name, e.g.

listenSocket.SetSocketOption(..., SocketOptionName.MaxConnections, ...);

In contrast, as a backlog argument it is meant to be used.

like image 141
Roland Pihlakas Avatar answered Oct 20 '22 10:10

Roland Pihlakas