Skip to main content
Explorer
October 15, 2024
Question

Mutliple TCP clients on STM32H563 with NetXDuo

  • October 15, 2024
  • 1 reply
  • 1529 views

I have a question regarding the tutorial "Handling multiple TCP clients on STM32H563 with NetX Duo" written by @STea .

See https://community.st.com/t5/stm32-mcus/handling-multiple-tcp-clients-on-stm32h563-with-netx-duo/ta-p/695030

 

In the first section "handling multilple clients on the same port", there is some example code. In the function

static VOID tcp_thread_entry(ULONG thread_input)

there is an infinite loop, containing a tx_queue_receive call:

 /* Receive pointers to TCP socket and network packet from TCP callback */
 ULONG msg[2];
 status = tx_queue_receive(&g_tcp_q, msg, TX_WAIT_FOREVER);

At the moment I try to create an application based on this tutorial. Apparently, the tx_queue_receive fails (returns TX_QUEUE_ERROR) which makes sense, since no one sends data into the queue "g_tcp_q". At which point should this happen? I can't find it in the example code.

 

Furthermore, the tutorial states "You can find attached the file app_netxduo++clients_same_port.c that you can replace in this project to test this use case.". I can't find it.

 

    This topic has been closed for replies.

    1 reply

    ST Employee
    October 15, 2024

    Hello @SiSte ,

    the queue receives message from the receive callback 
    here is the section where it gets messages published to thread app 

    static void g_tcp_sck_receive_cb(NX_TCP_SOCKET * p_sck)
    {
     NX_PACKET * p_packet;
    
     /* This callback is invoked when data is already received. Retrieving
     * packet with no suspension. */
     nx_tcp_socket_receive(p_sck, &p_packet, NX_NO_WAIT);
    
    #if APP_TCP_LOG
     ULONG ip, client_port;
     nx_tcp_socket_peer_info_get(p_sck, &ip, &client_port);
     printf("[TCP %x] Incoming packet (%lu bytes) from %lu.%lu.%lu.%lu:%lu\n\r",
     p_sck, p_packet->nx_packet_length, (ip >> 24) & 0xFF,
     (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, (ip) & 0xFF, client_port);
    #endif
    
    #if APP_TCP_INSTANT_ECHO
     /* Send packet back on the same TCP socket */
     nx_tcp_socket_send(p_sck, p_packet, NX_NO_WAIT);
    #else
     ULONG msg[2] =
     {
     (ULONG) p_sck, (ULONG) p_packet
     };
    
     /* Sent TCP socket and packet pointers to user thread */
     if (TX_SUCCESS != tx_queue_send(&g_tcp_q, msg, TX_NO_WAIT))
     {
     nx_packet_release(p_packet);
     }
    #endif
    }

     and you are right the attached are missing from the article sorry for the inconvenience and here is the file attached.

    Regards

     

    SiSteAuthor
    Explorer
    October 15, 2024

    Thanks for your fast reply. Regarding the TX_QUEUE g_tcp_q:

    As far as I understand ThreadX, it is required to call "tx_queue_create()" before calling send or receive on the queue.

    I can't see this call in our code, might this be the reason for getting a TX_QUEUE_ERROR returned from tx_queue_receive()?