2 Replies Latest reply on May 11, 2016 6:35 PM by jayi

    wiced_tcp_connect causing hang

    mdelbo

      Hi, if I purposely stop my tcp server so the socket doesn't connect, this app stops after the second iteration of the while loop. Am I doing something wrong?

       

      #include "wiced.h"
      
      
      static wiced_tcp_socket_t tcp_client_socket;
      
      
      void application_start( )
      {
        const unsigned long ip_address = MAKE_IPV4_ADDRESS(192,168,0,11);
        const unsigned long port = 5011;
        const wiced_ip_address_t INITIALISER_IPV4_ADDRESS(server_ip_address, ip_address);
      
      
        wiced_init();  
        while ( 1 ) { 
          wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);
          wiced_result_t result;
          result = wiced_tcp_create_socket(&tcp_client_socket, WICED_STA_INTERFACE);
          wiced_tcp_bind(&tcp_client_socket, port);
          wiced_tcp_connect(&tcp_client_socket, &server_ip_address, port, 2000);
          if (result == WICED_SUCCESS) {
            WPRINT_APP_INFO(("DISCONNECT\n"));
            wiced_tcp_disconnect(&tcp_client_socket);
          }
          wiced_tcp_delete_socket(&tcp_client_socket);
          wiced_network_down(WICED_STA_INTERFACE);
        }
      }
      

       

      I've tested and get the same result using both WICED-SDK-3.3.1 & WICED-SDK-3.5.2. If I remove the wiced_tcp_connect call then the loop continues indefinitely.

        • 1. Re: wiced_tcp_connect causing hang
          mdelbo

          I should mention, the above code works fine if my top server is up.

          • 2. Re: wiced_tcp_connect causing hang
            jayi

            Hello Michael,

             

            Which board and network stack are you using? I've tried your code on my BCM943341WCD1 on ThreadX/NetX_Duo and cannot replicate the issue. It simply retries the tcp connection again if the server is down.

             

            I've noticed in your code that the return variable is assigned to

            wiced_tcp_create_socket() and not wiced_tcp_connect().

             

            Do your results change if you assign result =  wiced_tcp_connect()?

             

            For reference, on NetX_Duo the code still goes through fine in my environment whether or not the result variable is correctly assigned.

             

            Thanks,

            Jaeyoung