Apollo3zehn / FluentModbus

Lightweight and fast client and server implementation of the Modbus protocol (TCP/RTU).
MIT License
189 stars 71 forks source link

ModbusTcpServer.MaxConnections not working #35

Closed mkroesen closed 3 years ago

mkroesen commented 3 years ago

I have set MaxConnections = 2 but more connections can be established without problems and I also receive data.

grafik

Have I configured something wrong? I would be happy about a solution.

Apollo3zehn commented 3 years ago

I will also check that in Monday :-) in my tests it is working but I test again with your setup/client.

Apollo3zehn commented 3 years ago

There was a wrong greater than / greater equal check and I used the lock keyword incorrectly which allowed the connection of more than the limited number of clients when they connect at the same time. I am not sure if that solves your issue but in my tests it worked (tested with Modbus Poll as you did). The found issues have been solved in release 2.2.1 (https://www.nuget.org/packages/FluentModbus/2.2.1).

Apollo3zehn commented 3 years ago

It looks like that you are creating multiple connection in the same Modbus Poll application (4 child windows in one main window). Maybe Modbus Poll is reusing the connection. I have tested it with four independent Modbus Poll windows.

mkroesen commented 3 years ago

It works now but I can always use one more connection than indicated. If MaxConnections = 2, I can use 3 connections, MaxConnections = 3 I am able to use 4 etc.

Apollo3zehn commented 3 years ago

I have found the reason why one connection more than expected is accepted and will release a fixed version soon.