I have created a Modbus TCP Server application as an MQX task, which runs over RTCS TCP/IP. This task works very well for a single Modbus TCP Client connection.
It detects a connection via accept(), receives Modbus command packets via recv() and sends Modbus response packets via send(). The task also uses closesocket() to close the connection, when either no Modbus Commands are received (timeout) or by detecting that the Modbus TCP Client has closed the connection.
Since accept() always blocks until a connection occurs, I can't easily modify my task to handle multiple concurrent connections.
What is the best (and simplest) way to handle multiple concurrent TCP connections on the same port (TCP port 502 in this case)?