rossmann-engineering / EasyModbusTCP.NET

Modbus TCP, Modbus UDP and Modbus RTU client/server library for .NET implementations
928 stars 402 forks source link

When the TCP server is disconnected #49

Open NowUp opened 3 years ago

NowUp commented 3 years ago

Hello, In the process of using, I found a problem, this problem seriously affected the use.

In the state of connection, when the server TCP terminates the service, no abnormal feedback is received in any read and write operation of the client, the value of Connected property is true, and after the server service is restarted, it still cannot operate normally.

I used Modbus Slave for TCP communication simulation.

BatangTurun commented 3 years ago

I had the same concern, what to do if the connection (LAN) went down.

My solution was to ping the TCP device every 500mS to test for connection and take appropriate action if LAN went down.

For example Set Disconnect and then Connect when the LAN is backup.

Padanian commented 3 years ago

Same here. I ping it every 1000ms to keep the socket open

rossmann-engineering commented 3 years ago

Yes that is indeed in issue, which can't be reliably solved (At least I don't know how). That happens if the connection breaks up, without properly closing it. Any request should run into a timeout. It is usually the way to reconnect if any exception is thrown. Also there is the "Available" Method which pings the server to check for its availability.