Modbus TCP Listener question

The ModbusTcpListener function is as follows:

public ModbusTcpListener(ModbusDevice device, int port, int maxConnections, short maxDataLength) {
            this.device = device;
            this.maxDataLength = maxDataLength;
            this.listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.listenSocket.Bind(new IPEndPoint(IPAddress.Any, port));
            this.listenSocket.Listen(1);
            this.listenThread = new Thread(this.ListenProc);
            this.listenThread.Start();
        }

maxConnections is not used anywhere. Should it not be used at:
this.listenSocket.Listen(maxConnections) instead of ‘1’?

The number in the Listen method is not the maximum number of active connections but rather the number of pending connections allowed. A pending connection is one that is just starting up. If a second connection tries to connect, and the number is 1, then it will be rejected. If the Listen queue size is greater than one, then additional connections will queue until the older ones are completed.

This just involves starting a connection, not the maximum number of simultaneous connections.

I usually set the listening number to 5. Completing an Accept() is milliseconds.

1 Like

Where does maxConnections get used then? I don’t see where it is referenced after it is passed into the function.

If this is a problem for you open a issue on Github.

I don’t think it’s a problem. I am just trying to understand how it works and what limits there are.