Note that there are some explanatory texts on larger screens.

plurals
  1. POModbus TCP Client closes the connection because of unexpected answer from my server implementation
    text
    copied!<p>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.</p> <h2>Implementation description</h2> <ul> <li>The server is multithreaded, one thread manages the SOCK_STREAM socket for receiving frames</li> <li>select is used out of efficiency reasons</li> <li>A semaphore is used for preventing concurrent access on socket resource while sending or receiving</li> <li>Encapsulation of Modbus upper layer is done transparently through send and receive methods, it is only a matter of building a frame with the right header and payload anyway...</li> <li>Another threads runs, inside it, Modbus send and receive methods are invoked. </li> </ul> <h2>TCP Context</h2> <p>TCP is up and running, bound to a port, max client set and listening.</p> <p>Traces under wireshark show:</p> <ul> <li>Client: SYN </li> <li>My app Server: SYN, ACK </li> <li>Client: ACK</li> </ul> <p>On the server side a brand new socket has been created as expected and bound to the client socket.</p> <p><strong>So far, all is good.</strong></p> <h2>Modbus Context</h2> <ul> <li>Client: Send Modbus frame, TCP flags = 0x18 which is ACK + PUSH</li> <li>My app Server: <strong>Does not wait and send a single empty TCP ack frame</strong>.</li> <li>Client: Waits for a modbus frame with tcp ack flag. Therefore, takes it as an error and asks to closes the connection.</li> </ul> <p>Hence, my server software cannot send any actual response afterwards as the socket on the client side is being closed or is already closed.</p> <h2>My problem</h2> <ul> <li>I receive a modbus frame that the main thread need to process (server side)</li> <li>Processing takes a few ms, in the meantime a TCP ACK frame is sent through my server socket, whereas I would like it not to send anything !</li> </ul> <p>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. </p> <p>If you have any suggestion I am very interested... I hope I am clear enough.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload