Skip to main content
Graduate
February 1, 2024
Solved

How to tune azure netxduo to receive more incoming connections?

  • February 1, 2024
  • 4 replies
  • 8181 views

Hello,

I am using the stm32h563 processor in my project. I made a TCP Server application using the ethernet connections of this processor and I was able to run it as I wanted. But I saw that it could not connect to another client over the same IP address without breaking the connection with one client. Even though I set the NX_MAX_PHYSICAL_INTERFACES defined value to two, there was no change. Also, in the files I shared, it is said that we can make a tcp server and 2 tcp client connections and open a separate socket for each (1).

 

After some research, I realized that this problem can be solved with lwip + freertos. Below are examples of these solutions. How can I make a similar solution on Azure RTOS Netx side?
Our problem with lwip + freertos solved community issue(2) was previously shared and the solution was "By tweaking the options in lwipopts.h, it should be possible to receive more incoming connections: MEMP_NUM_TCP_PCB, MEMP_NUM_TCP_PCB_LISTEN, MEMP_NUM_NUM_NETCONN, etc... " was returned as ".

As a similar header you can see the extension(3) under the References header.

 

References:

(1)Understand Azure RTOS NetX Duo | Microsoft Learn

(2)Solved: How to tune LwIP to receive more incoming connecti... - STMicroelectronics Community

(3) I hope to achieve one-to-many connections using TC... - STMicroelectronics Community

 

Best Regards

Eren Akyol

    This topic has been closed for replies.
    Best answer by STea

    Hello  @Eakyo.1 ,

    I've prepared a small template file app_netxduo.c from which I was able to send data with multiple clients on the same IP address and port.

    STea_0-1719507529388.png

    Find attached the template File and confirm if this what you need to do.
    Regards


    4 replies

    ST Employee
    February 7, 2024

    Hello @Eakyo.1 ,

    I need to get more insights to help you with your further implementation of Netxduo .

    are you using the following API call to accept an incoming client connection:

    NX_TCP_SOCKET client_socket;

    nx_tcp_server_socket_accept(&server_socket, &client_socket, NX_WAIT_FOREVER);

    then you should create a new thread to handle the client connection with :

    tx_thread_create(.....);

    if it is the case could you explain the exact behavior from STM32 side when trying to connect the new client .

    BR

    Hichem

    Eakyo.1Author
    Graduate
    June 24, 2024

    Hello @STea ,

    Actually, if you run the TCP/IP Server Echo application from the link I shared below, only one client connects to the defined IP and Port. Despite setting the NX_MAX_PHYSICAL_INTERFACES value to 4 and calling the "nx_ip_interface_attach" function, only one client can still connect in the TCP/IP Server Echo application; only one client can connect at a time. The requirement of my project is that multiple clients can send queries to a single IP and Port.

    https://github.com/STMicroelectronics/STM32CubeH5/tree/main/Projects/STM32H573I-DK/Applications/NetXDuo/Nx_TCP_Echo_Server

    ST Employee
    June 24, 2024

    Hello @Eakyo.1 ,

    Can you please share the code in which you are declaring and binding you TCP sockets. I assume it's located in your app_netxduo.c.

    Regards

    ST Employee
    June 25, 2024

    Hello @Eakyo.1 ,

    In order to achieve multiple socket TCP connection, you need to create a thread for each socket, and you need to adjust some parameters to make for the Nextduo pool sizes as well as passing the Port or an index (as attached) to handle multiple connection ...

    bellow you will find both app_netxduo.c and app_netxduo.h which I used to test this is working.

    as you mentioned for the Lwip solution for number of sockets that should be increased the parameter for Nexduo is #define MAX_TCP_CLIENTS 5 (example)

    Regards

     

    Eakyo.1Author
    Graduate
    June 26, 2024

    Hello @STea ,

    First of all, thank you very much for your help. In the example you provided, 2 different clients can connect to 2 different ports with the same IP. Actually, what I've been trying to explain from the beginning is that 2 different clients should be able to connect to a single port with the same IP. Do you have any suggestions for this?

    Regards

    ST Employee
    June 26, 2024

    Hello @Eakyo.1 ,

    To allow multiple clients to connect to a single server port, you typically use a single listening socket that accepts incoming connections. Each accepted connection is then handled by a separate socket. This is a common pattern in TCP server design. is this what you are trying to do?

    In that case you need to:

    1. Create a Listening Socket: This socket listens for incoming connection requests on the server port.

    2. Accept Connections: When a client attempts to connect, the server accepts the connection, which creates a new socket specifically for communicating with that client.

    3. Handle Client Communication: The server communicates with the client using the newly created socket. This communication is often handled in a separate thread or by using asynchronous I/O to allow the main listening socket to continue accepting new connections.

    4. Manage Multiple Connections: If you want to handle multiple connections simultaneously, you can create a new thread for each accepted connection, or you can use a select/poll mechanism to manage multiple sockets within the same thread.

    Regards

    STeaAnswer
    ST Employee
    June 27, 2024

    Hello  @Eakyo.1 ,

    I've prepared a small template file app_netxduo.c from which I was able to send data with multiple clients on the same IP address and port.

    STea_0-1719507529388.png

    Find attached the template File and confirm if this what you need to do.
    Regards


    Eakyo.1Author
    Graduate
    July 2, 2024

    Hello @STea ,

    Yes, this is exactly what I wanted. Thank you very much for your help.

    Regards