Hi,
I use MQX with RTCS V4.2 in My system which provides a Modbus TCP server and supports four connections at same time.
There is a problem of my system when there is a connection is closed and another connection is setup in a short time, for example, no more than 2 milliseconds. The problem is the connection which should be closed will send out data using the new setup socket.
I try to investigate this issue and use following code to check the socket I will use:
CurPort = ((struct tcb_struct *)(((struct socket_struct *)Modbus_sock)->TCB_PTR))->SOCKET;
Modbus_sock is the socket I got form the accept function, I use this socket to read the socket stored in the TCB. If there is no problem, the socket read from the TCB is always correct, but when there is an error, the value I got is 0 or 3725.
Did someone got this problem before? Or can give me some tip about this issue.
Thank you very much!
Martin
Hi Martin:
Some information.
There are two ways for you to shut down a socket. One is shutting down gracefully. By default, RTCS maintains the socket connection for two seconds after the remote endpoint disconnects.. The other is shutting down with an abort operation. RTCS immediately discards the socket and the socket's internal send and receive buffers. I would suggest you try to use the second way to shutting down the socket. The SO_LINGER socket option indicates how the socket is to be shut down: either gracefully or with an abort operation (TCP reset).
Regards
Daniel
Hi Daniel,
in which case can cause the problem mentioned by Martin? As you know, in user application the TCBs may be not cared.