1 Reply Latest reply on Mar 27, 2014 5:39 AM by userc_2167

    TCP Server with multiple sockets on AP interface

      Hi!

       

      I'm running a TCP server on Wiced AP interface and there are some issues with that when wanting to have multiple of sockets at the same time. I'm using ThreadX NetX-Duo.

       

      Wiced has a wrapper API for TCP socket listen that defaults to the STA interface:

       

      wiced_result_t wiced_tcp_listen( wiced_tcp_socket_t* socket, uint16_t port );

       

      This has to be modified if you want to use the AP interface. Please add a new API or add interface parameter to the existing one.

       

      Please consider adding:

       

      wiced_result_t wiced_tcp_listen_ap( wiced_tcp_socket_t* socket, uint16_t port );

       

       

      wiced_result_t wiced_tcp_listen_ap( wiced_tcp_socket_t* socket, uint16_t port )

      {

          tcp_listen_callback_t listen_callback = NULL;

          struct NX_TCP_LISTEN_STRUCT* listen_ptr;

          WICED_LINK_CHECK( socket->socket.nx_tcp_socket_ip_ptr );

       

       

          /* Check if there is already another socket listening on the port */

          listen_ptr = IP_HANDLE(WICED_AP_INTERFACE).nx_ip_tcp_active_listen_requests;

          if ( listen_ptr != NULL )

          {

              /* Search the active listen requests for this port. */

              do

              {

                  /* Determine if there is another listen request for the same port. */

                  if ( listen_ptr->nx_tcp_listen_port == port )

                  {

                      /* Do a re-listen instead of a listen */

                      if ( nx_tcp_server_socket_relisten( socket->socket.nx_tcp_socket_ip_ptr, port, &socket->socket ) == NX_SUCCESS )

                      {

                          return WICED_SUCCESS;

                      }

                      else

                      {

                          return WICED_ERROR;

                      }

                  }

                  listen_ptr = listen_ptr->nx_tcp_listen_next;

              } while ( listen_ptr != IP_HANDLE(WICED_AP_INTERFACE).nx_ip_tcp_active_listen_requests);

          }

       

       

          /* Check if this socket has an asynchronous connect callback */

          if (socket->callbacks[WICED_TCP_CONNECT_CALLBACK_INDEX] != NULL)

          {

              listen_callback = internal_tcp_listen_callback;

          }

       

       

          if (socket->socket.nx_tcp_socket_state != NX_TCP_CLOSED)

          {

              nx_tcp_server_socket_unaccept( &socket->socket );

              if ( nx_tcp_server_socket_relisten( socket->socket.nx_tcp_socket_ip_ptr, socket->socket.nx_tcp_socket_port, &socket->socket ) == NX_SUCCESS )

              {

                  return WICED_SUCCESS;

              }

              else

              {

                  return WICED_ERROR;

              }

          }

          else

          {

              if ( nx_tcp_server_socket_listen( socket->socket.nx_tcp_socket_ip_ptr, port, &socket->socket, WICED_DEFAULT_TCP_LISTEN_QUEUE_SIZE, listen_callback ) == NX_SUCCESS )

              {

                  return WICED_SUCCESS;

              }

              else

              {

                  return WICED_ERROR;

              }

          }

      }

        • 1. Re: TCP Server with multiple sockets on AP interface

          You're right, thanks for reporting this.

           

          A separate API shouldn't be necessary though because the socket is created using the function wiced_tcp_create_socket( wiced_tcp_socket_t* socket, wiced_interface_t interface ) which is created for a particular interface. The right approach is to grab the interface info from the socket object instead of having it hardcoded as STA. We'll fix this up in the next release.