12 Replies Latest reply on Oct 20, 2014 2:43 PM by userc_6496

    TCP socket - data send problem

      Hi,

       

             I am using a WICED Wifi board. I have been trying to send data to the server through TCP socket every 2 seconds. I could get the connection between the server and board established and I was also able to sent data through the established socket. But after some random time, the sending function failed though the connection was still alive.

       

      A more elaborate explanation of my problem is below.

       

             I created the socket, binded it to a port and established the connection with the server. I created the packet using wiced_packet_create_tcp() and sent the data using wiced_tcp_send_packet() every 2 seconds. The server was able to receive the data. This went fine only for sometime. After that the wiced_tcp_send_packet() function fails each time. I took care of deleting packet using wiced_packet_delete().


           Next, I used wiced_tcp_send_buffer() instead of wiced_tcp_send_packet(). Same problem.


           I also used wiced_tcp_stream_init(), wiced_tcp_stream_write() and wiced_tcp_stream_flush() functions to send data, instead of the above functions. Still it's the same.

           Is anything missing or there is some problem in WICED API of sending tcp packet.

       

      Thanks

        • 1. Re: TCP socket - data send problem

          I don't see this issue in my experience.

          Which network stack do you use?

          Is it possible to share your reproducible application code like snip.tcp_client?

          • 2. Re: Re: TCP socket - data send problem

            Thank you for your reply.

             

            The send function which I am using is posted below. This function sends the string "Hello" to the server every time it is called.

             

            wiced_result_t tcp_send_data(void *arg)
            {
              printf("I am in send function\r\n");
              UNUSED_PARAMETER( arg );
              wiced_packet_t*          packet;
              char*                    tx_data;
              uint16_t                 available_data_length;
              /* Create the TCP packet. Memory for the tx_data is automatically allocated */
              if (wiced_packet_create_tcp(&tcp_client_socket, TCP_PACKET_MAX_DATA_LENGTH, &packet, (uint8_t**)&tx_data, &available_data_length) != WICED_SUCCESS)
              {
                 WPRINT_APP_INFO(("TCP packet creation failed\r\n"));
                 return WICED_ERROR;
              }
              sprintf(tx_data, "%s", "Hello\r\n");
              /* Set the end of the data portion */
              wiced_packet_set_data_end(packet, (uint8_t*)tx_data + strlen(tx_data));
              /* Send the TCP packet */
              if (wiced_tcp_send_packet(&tcp_client_socket, packet) != WICED_SUCCESS)
              {
                 WPRINT_APP_INFO(("TCP packet send failed\r\n"));
                 /* Delete packet, since the send failed */
                 wiced_packet_delete(packet);
                 /* Close the connection */
                 wiced_tcp_disconnect(&tcp_client_socket);
                 return WICED_ERROR;
              }
              wiced_packet_delete(packet);
              return WICED_SUCCESS;
            }
            
            

             

            In application_start(), I am calling this function every 500ms using a register timed event. 

            I am using the tcp_echo_server.py given by snip.tcp_client as server.

             

            In client side, I am getting the following output.

             

            
            
            Platform BCM943362WCD4 initialised
            Started ThreadX v5.5
            Initialising NetX v5.6
            Creating Packet pools
            Starting Wiced v2.4.0
            WWD SDIO interface initialised
            WLAN MAC Address : 40:2C:F4:AF:31:05
            Joining : hbbtv
            Successfully joined : hbbtv
            Obtaining IPv4 address via DHCP
            Setting IPv6 link-local address
            IPv4 network ready IP: 192.168.0.101
            Back to main function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            I am in send function
            TCP packet creation failed
            I am in send function
            TCP packet creation failed
            I am in send function
            TCP packet creation failed
            I am in send function
            TCP packet send failed
            I am in send function
            TCP packet send failed
            I am in send function
            TCP packet send failed
            I am in send function
            TCP packet send failed
            I am in send function
            TCP packet send failed
            *****Packet sending fails after this**********
            
            
            
            

             

            In server side,

             

            
            TCP echo server
            Listening on: :50007
            Incoming connection accepted:  ('192.168.0.101', 50007)
            Feb 26 14:34:17  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:17  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:18  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:18  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:19  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:19  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:20  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:20  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:21  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:21  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:22  192.168.0.101 : 'Hello\r\n'
            
            
            Feb 26 14:34:34  192.168.0.101 : 'Hello\r\n
            
            
            Feb 26 14:34:34  192.168.0.101 : 'Hello\r\n'
            
            
            Traceback (most recent call last):
              File "tcp_echo_server.py", line 66, in <module>
                echo_server(options.hostname, options.port)
              File "tcp_echo_server.py", line 46, in echo_server
                data = conn.recv(4096)
            socket.error: [Errno 104] Connection reset by peer
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            

             

             

            Thanks.

            • 3. Re: Re: TCP socket - data send problem

              I found a problem with your function: You must not delete the packet if the send function is successful.

              Once you pass your packet to the send function you lose ownership of that packet unless the send failed in which case the packet ownership is returned to you.

              • 4. Re: TCP socket - data send problem

                I've removed deleting packet after successful send.

                But this issue still exists.

                • 5. Re: TCP socket - data send problem

                  Hi,

                   

                  I too have removed the delete packet function after successful send. The issue still exists.

                   

                  Thanks.

                  • 6. Re: TCP socket - data send problem
                    GregG_16

                    Is this still an issue?

                    • 7. Re: TCP socket - data send problem
                      SuLe_1710756

                      Hi, gangi

                       

                      Our customer has also met this same issue("TCP socket error") as raghu1991 said.

                      I verified this issue with BCM943362WCD4 + SDK 3.0.1 and "tcp_server" application.

                      And then, I changed tcp_server_thread_main() function in tcp_server.c as follows,

                       

                      if ( result == WICED_SUCCESS )

                      {

                              /* Receive the query from the TCP client */

                              if (wiced_tcp_receive( &server->socket, &temp_packet, WICED_WAIT_FOREVER ) == WICED_SUCCESS)

                              {

                      #if 1   // for test

                                  while( tcp_server_process( server, temp_packet ) == WICED_SUCCESS )

                      #else

                                  /* Process the client request */

                                  tcp_server_process( server, temp_packet );

                      #endif

                                  /* Delete the packet, we're done with it */

                                  wiced_packet_delete( temp_packet );

                                  ......

                      }

                       

                      As this results, "TCP packet send failed" error occurred as follows,

                       

                      Creating tcp server thread

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      Echo data: Hello Wiced!

                      Received data: Hello Wiced!

                      TCP packet send failed

                       

                      Could you let me know how to resolve this issue?

                       

                      Thanks,

                      SM

                      • 8. Re: TCP socket - data send problem
                        SuLe_1710756

                        Hi, raghu1991

                         

                        I have also met this issue with you. May I ask whether you resolved it and how to resolve?

                         

                        Thanks,

                        SM

                        • 9. Re: TCP socket - data send problem

                          Hi sung-mok_lee,


                          The issue seems to be resolved. We changed the Wifi router which we were using and it worked.

                           

                          Also the tcp_echo_server.py echoes the data back to board. But I was not receiving it in my function. So I removed the echo part in tcp_echo_server.py.

                           

                          Now it is working without any problem.

                          • 10. Re: Re: TCP socket - data send problem

                            Has anyone else found a solution to this problem?  Telling customers to buy a different router is not a workable solution for us...

                            • 11. Re: Re: TCP socket - data send problem
                              SuLe_1710756

                              Hi bshaya,

                               

                              I found this issue when I tested tcp communication in using ThreadX and NetX and SDK 3.x. However, this issue was resolved by using FreeRTOS and LwIP. I think FreeRTOS and LwIP seems to be more stable. I hope this comments would helpful for you.

                               

                              Thanks,

                              Sung-Mok Lee

                              • 12. Re: Re: TCP socket - data send problem

                                Interesting.  I tested with FreeRTOS and LwIP on 3.0.1 and found it to be much more stable.  I just upgraded to 3.1.1, and preliminary testing seems to indicated that FreeRTOS and LwIP are much less stable than they were in 3.0.1 while NetX is now satisfactory... I wonder what happened...