elnoonio
elnoonio

Reputation: 1

Modbus TCP Client closes the connection because of unexpected answer from my server implementation

I have implemented a Modbus over TCP as server software in Python. App is multithreaded and relies heavily on standard libs. I have problems managing the connection on the server side. Meanwhile my implementation as Modbus over TCP as client works just fine.

Implementation description

TCP Context

TCP is up and running, bound to a port, max client set and listening.

Traces under wireshark show:

On the server side a brand new socket has been created as expected and bound to the client socket.

So far, all is good.

Modbus Context

Hence, my server software cannot send any actual response afterwards as the socket on the client side is being closed or is already closed.

My problem

Do you have any idea on how to manage the ACK behavior ? I have read stuff about the naggle algorithm, but it does not seem to be in the scope of the problem here... I'm not sure that any option of the setsockopt method would solve my problem also, but I may be mistaken.

If you have any suggestion I am very interested... I hope I am clear enough.

Upvotes: 0

Views: 3139

Answers (1)

Neal
Neal

Reputation: 6992

It seems like a strange requirement that all TCP packets must contain a payload as this is very difficult to control unless you are integrated with the TCP stack. If it really is the case that the client crashes because the ACK has no Modbus payload, I think the only thing you can do from python is try disabling the TCP_QUICKACK socket option so that TCP waits 500ms before sending an ACK. This obviously won't work in all cases (or may not at all if it takes your code > 500ms to create a response), but I don't know of any other options using the socket API from python.

This SO answer tells you how to disable it: Disable TCP Delayed ACKs. Should be easy to figure out how to enable it from that. Note, you need to constantly re-enable it after receiving data.

Upvotes: 0

Related Questions