I’m using the TCP_SOCKET function block as a TCP client. I can establish a connection to the server. But if the server closes the connection, the client doesn’t recognise it (there is no error or sth similiar). Is it correct, that the TCP_SOCKET (client) doesn’t recognise a closing/closed connection by the server? I’m using PLC Engineer 2020.6.2 and a AXC-F-1152 with FW 2020.0.1 LTS (20.0.1.26832) Many thanks!
Hi beecksche, I’ve tried that case a few month ago in a Modbus TCP Client/Server communication.
Even when I’ve made the tests with FW 2020.3 it should work in 2020.0 ether. Basically the Socket should work as follows:
* If the partners closes the connection, there should be an error code and the error output turns true. * If the partner is not responding (e.g. power off), does the PLC send 3 keep alives (10s each --> 30s total) and will close the session after the timeout.Also in that case you should get a valid error code and the error should turn true. Keep in mind that the errorcode is only valid, when the error output is true, maybe you will not even recognize it in debug mode.
I recommend to trigger on the error output and store the error code on a rising edge. If this won’t work you can record on the PLC the traffic via tcpdump (Tutorial on Youtube) and send the record with the project to me (Ticket #201295).
- → fwalde@phoenixcontact.com Take care, Frank
With Frank’s help, we’ve found out that the TCP_SOCKET sets an error and start reconnecting, only if the HANDLE and ACTIVE slots are connected to a TCP_RECEIVE function block. Here is a MWE
Without the TCP_RECEIVE function block, the TCP_SOCKET (client) do not recognise a disconnect by the server.