2024-06-23 08:33 AM
In my project, I have a TCP/IP server application running. My main problem is that only one client can connect to the same IP and port at the same time. My project requirement is that multiple clients should be able to send queries to the same IP and port. I can achieve this structure with LWIP, but I couldn't set up the same structure with Azure RTOS NetX. One client works without a problem, but multiple clients cannot send queries. What can we do about this?
Solved! Go to Solution.
2024-06-25 07:25 AM
Hello @Eakyo.1 ,
This issue was addressed in this thread How to tune azure netxduo to receive more incoming... - STMicroelectronics Community.
Regards
2024-06-23 08:41 AM
I set the value of NX_MAX_PHYSICAL_INTERFACES to 4 and used the nx_ip_interface_attach function. I tried this in the TCP/IP server echo project you shared for the STM32H5, and only one client could connect to the same IP and port. Multiple connections are not possible. If you have a solution for this, could you please share it with me in the TCP/IP server echo project you provided?
2024-06-23 09:27 AM - edited 2024-06-24 04:45 AM
The same principles apply to NetX as they do in LWIP or any Sockets interface.
If you want to handle multipl connections concurrently, then after the server calls the equiv of `accept()`
you have to spawn a new thread to handle the communication on that connection. That way, the main thread
can call immediately call listen() again and be ready for a new connection.
In the Echo Server example, after the call to `nx_tcp_server_socket_accept`, the main thread goes into a while(1) loop and talks to the connected client until it disconnects.
There is a "cheat" which may or may not suit your needs. The socket interface usually support a configurable-length "queue" of pending clients. So that if a client tries to connect while the server is dealing with another connection, hey are not refused, they simply block (on their side). If you can guarantee that each client will connect, have a brief exchange with the server, and then disconnect, you can get away with having just one main thread. But be this usually ends up not being good enough. It also isn't resilient to any errors (if a client dies, you server will stall until a timeout occurs, for example, which can be many seconds or even more).
Newer network stacks (in general) use an "event-loop" and an async model of network programming, I don't know if the NetX API supports something like this. These APIs tend to scale better and use less memory (maybe), but there's a learning curve and it can be harder to debug your code.
2024-06-24 04:21 AM
Hi @BarryWhit ,
Thank you for your feedback. As I understand it, to handle multiple connections concurrently in the NetX API, we need to spawn a new thread after each connection acceptance. I have a few questions to better understand and implement this method:
Example Code: Could you provide an example code snippet for starting a new thread after the nx_tcp_server_socket_accept function and managing the connection within this thread? This would help me integrate this structure into my current Echo Server project.
Event-Loop and Asynchronous Programming: You mentioned that newer network stacks support an event-loop and an asynchronous model of network programming. Could you provide more information on whether the NetX API supports these features? If it does, could you guide me on how to implement it in my current project or suggest some resources?
I would appreciate your feedback on these topics. Thank you again for your help.
Best regards,
2024-06-24 04:46 AM - edited 2024-06-24 04:46 AM
No. You'll have to do that yourself.
2024-06-24 05:55 AM
Same question here:
:thinking_face:
2024-06-25 07:25 AM
Hello @Eakyo.1 ,
This issue was addressed in this thread How to tune azure netxduo to receive more incoming... - STMicroelectronics Community.
Regards