libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

Dead connections

Open Tangerino opened this issue 6 years ago • 4 comments

How do we detect dead connections on a modbus server? How to avoid clients to connect and not send data or became unresponsive? Server may drop the connections from lazy clients. Thanks in advance

Tangerino avatar Dec 21 '17 14:12 Tangerino

From the documentation: http://libmodbus.org/docs/v3.0.6/modbus_read_registers.html or http://libmodbus.org/docs/v3.1.4/modbus_read_registers.html

The modbus_read_registers() function shall return the number of read registers if successful. Otherwise it shall return -1 and set errno.

If not connected or read fails, try to reconnect and read again.

Remote devices/servers that fail often can drastically affect the total efficiency of the entire MODBUS network. Especially with RTU/serial networks. It is just the nature of a master/slave type of network.

From: Carlos Tangerino [mailto:[email protected]] Sent: Thursday, December 21, 2017 9:21 AM To: stephane/libmodbus [email protected] Cc: Subscribed [email protected] Subject: [stephane/libmodbus] Dead connections (#415)

How do we detect dead connections on a modbus server? How to avoid clients to connect and not send data or became unresponsive? Server may drop the connections from lazy clients. Thanks in advance

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stephane/libmodbus/issues/415 , or mute the thread https://github.com/notifications/unsubscribe-auth/AAo5AXSH6sxTcu9UdFfo602UypJEa0IZks5tCmkxgaJpZM4RJ4hx . https://github.com/notifications/beacon/AAo5AXGx3bolubnyh0mv9uEZElXWyhaAks5tCmkxgaJpZM4RJ4hx.gif

watsocd avatar Dec 21 '17 16:12 watsocd

Never mind, the multi client example does not handle timeouts if we connect AND do not send anything. That will allocate all available sockets. This solution is outside the library context. Anyway be aware that DOS attack is easy to reproduce. It would be nice to have a void *user_data in the context so we can associate a timer for instance for each connection and close an idle socket. I would change the SELECT call to accept a time out argument. Thank you.

Tangerino avatar Dec 23 '17 07:12 Tangerino

->main The client connection from 192.168.1.4 is accepted Connecting to 192.168.1.100:102 Waiting for a indication...

Excuse me, what's the reason for this?

fkgit avatar Jan 01 '18 04:01 fkgit

have you found the answer for this. I'm writing a server application and it works well. but if my client gets interrupted my slave program will hang and will not recover even if I cycle power on my client.

oazradSPOC avatar Nov 20 '20 00:11 oazradSPOC