2018-11-16 04:11 AM
Hi,
I would like to implement a Modbus TCP server based on the library cubeMX and LWIP with the ability of multiple client connections.
With only one client, it works perfectly well. With 2 clients, they can connect simultaneously but as soon as both send simultaneously a request, one of the 2 requests is discarded and it blocks the client.
I checked the LWIP statistics but everything seems ok.
I have to mention that I do not use a RTOS.
Browsing the net, I didn’t find any example of multiple connection without RTOS, does anyone already succeed implementing such behavior?
Many thanks in advance for your help
2018-11-16 09:52 AM
Yes, lwIP works well with and without RTOS.
You must create one listening connection, which stays active all the time and waits for incoming connections. For this listening connection You have to set up a callback function with tcp_accept(). When a new client wants to connect, IP stack creates a new data connection and calls Your accept callback with a pointer to this new data connections struct tcp_pcb. In accept callback You have to set up receive callback for each newly created data connection with tcp_recv() and accept this new connection by returning ERR_OK. Additionally there with tcp_arg() You can attach a custom data structure for each particular data connection, which also will be passed to receive callback function, if You need one.
Look for example at UM1713 section 4.1.2:
Also at section 5.1 in this:
2018-11-22 03:58 PM
Many thanks for this answer, I will try to follow your advices and rewrite the code in that direction.
Could you confirm that 2 simultaneously running communications (in modbus in this case) is perfectly achievable with LWIP on a stm32F407 microcontroller?
It has been weeks I'm looking for it now and I'm a little despaired of finding a solution.
It's disconcerting, because The 2 clients can be connected simultaneously, they can communicate with the server as well, but as soon as 2 requests (one from each client) arrive at the same time, one of the 2 requests is discarded. It has the consequence to block one of the 2 clients since it never receives the reply to its request.
I enabled the LWIP statistics, but I didn't see anything that can explain such behavior.
2023-08-31 03:24 PM
What test set up are you using to get this simultaneous connection and ping ?