This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

3200 tcp socket disconnect as tcpclient

Other Parts Discussed in Thread: CC3200

Hi,

    Now i use 3200 as a tcp client.

    I set 3200 as blocked.I wait to recive data,using sl_Recv(tcpclient_iSockID, recv_buf, TR_BUFF_SIZE, 0);

    When i shutdown the tcpserver.Follow is the packets.

As we know ,disconnect will through four times handshake.Clearly the above picture show it is not four times handshake.

But now sl_Recv is still blocked and not recive 0.So i can't judge the connect is disconnect.

If i set the tcp socket as ricive time out,I will recive 0 that the sl_Recv returned.

So how can i judge the disconnect,as tcpsocket blocked.

  • At the same time,the tcp keep alive is not working , (that should send keepalive packet after 300 seconds).
  • Hi,

    I'm sorry, but I'm not sure I understood your issue.
    Can you please provide a code snippet of what you are running and a wireless sniffer capture of the entire session, not just the last couple of packets?

    Thanks,
    Alon
  • Hi,

        Follow is my code:

    void usr_TcpClient(void *pvParameters)
    {
     SlSockAddrIn_t  sAddr;
     int             iAddrSize;
     int             iStatus;
     unsigned int dest_ip;
     unsigned short usr_port;

     start:

     usr_port=init_flash_temp[init_flash_netp_sta+65];  //
     usr_port<<=8;
     usr_port += init_flash_temp[init_flash_netp_sta+66];

     //filling the TCP server socket address
     sAddr.sin_family = SL_AF_INET;
     sAddr.sin_port = sl_Htons((unsigned short)usr_port);
     sAddr.sin_addr.s_addr = sl_Htonl(dest_ip);

     iAddrSize = sizeof(SlSockAddrIn_t);

     // creating a TCP socket
     tcpclient_iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
     if( tcpclient_iSockID < 0 )
     {
      usr_Report("creat tcp client err\r\n");
      sl_Close(tcpclient_iSockID);
      goto start;
     }

     unsigned long  enableOption = 1;
     sl_SetSockOpt(tcpclient_iSockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, &enableOption,sizeof(enableOption));

     struct SlTimeval_t timeVal;
     if(init_flash_temp[init_flash_pwr_sta+3]==0x00)// set recive time out
     {
      timeVal.tv_sec =  3;             // Seconds
      timeVal.tv_usec = 0;             // Microseconds. 10000 microseconds resolution
      iStatus = sl_SetSockOpt(tcpclient_iSockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal));    // Enable receive timeout
     }

     usr_Report("creat tcp client ok\r\n");
     while(1)
     {

      // connecting to TCP server

     
      vTaskDelay(1000);

      iStatus = sl_Connect(tcpclient_iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize);
      if( iStatus < 0 )
      {
       usr_Report("tcp client connect server ing\r\n");
       continue;
      }
      else
      {
       usr_Report("tcp client connect server success\r\n");

       tcp_connect_sta=0x0a;//connected


       while(1)
       {

        iStatus = sl_Recv(tcpclient_iSockID, recv_buf, TR_BUFF_SIZE, 0);//SL_POOL_IS_EMPTY

        if( iStatus <= 0 )
        {
         if(iStatus==0)
         {
          sl_Close(tcpclient_iSockID);
          usr_Report("tcp client disconnect the server\r\n");

          tcp_connect_sta=0x00;//dis

          goto start;
         }
         else
         {
          continue;
         }
        }
        else
        {
         usr_Report("tcp client recive num:#%d#\r\n",iStatus);
        
           //UART_PRINT("%d",iStatus);
           //
           uart_send_Ndata(UARTA0_BASE,recv_buf,iStatus);
       }
      }
     }
    }

    The issue is that if i set the socket as recive timeout (red code) ,i will recive 0 (sl_Recv return ),when i shut down the tcp server.

    If i don't set the socket as recive timeout ,i can't recive 0 (sl_Recv return ),when i shut down the tcp server.And it is still blocked in sl_Recv .

    I explain shuting down the tcpserver: I closed software directly,so the disconnect does not finish the four handsharks,and it is only two hansharks;Like the above picture.

    So if there is keepalive packets,it will check the disconnect.But i can't recive keepalive packets after more than 300 seconds.

    Is there other way to check the abnormal disconnect.

  • Hi,

    Sorry for the delayed response.

    We are looking into recreating this issue.
    We will try to update as soon as possible,

    Thanks,
    Alon

  • Hi,

    I've tested it, building the same setup.
    Once I close the server side, the simplelink device will immediately return from sl_Recv() with value 0.

    I didn't touch the keep alive or receive timeout options at all. Just using the default socket configuration (blocking mode).

    In order to try and help you, can you please provide me with your entire CC3200 project recreating the issue?
    If you have some server logic running on a PC that you can share, I'm also willing to have a look into that and running it in my setup.

    Thanks,
    Alon
  • Hi,

        Can you give me a e-mail,i send you a server soft ware.And you test use my software.

  • Hi,

    I've used your utility with my code and was able to see proper functionality of the simplelink device.
    Meaning, upon the socket was closed in the remote TCP server, the sl_Recv() immediately returned with value 0.

    The code I've tested is:
    {
    SlSockAddrIn_t Addr;

    _i16 sd = 0;
    _i16 AddrSize = 0;
    _i32 ret_val = 0;

    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons(80);
    Addr.sin_port = sl_Htons(5001);

    /* Change the DestinationIP endianity, to big endian */
    Addr.sin_addr.s_addr = sl_Htonl(appData.DestinationIP);

    Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(192,168,1,146));

    AddrSize = sizeof(SlSockAddrIn_t);

    sd = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    if( sd < 0 )
    {
    ASSERT_ON_ERROR(sd);
    }

    ret_val = sl_Connect(sd, ( SlSockAddr_t *)&Addr, AddrSize);
    if( ret_val < 0 )
    {
    /* error */
    ASSERT_ON_ERROR(ret_val);
    }

    ret_val = 1;
    while (ret_val>0)
    {
    ret_val = sl_Recv(sd, appData.Recvbuff, 100, 0);
    if( ret_val < 0 )
    {
    /* error */
    ASSERT_ON_ERROR(ret_val);
    }
    }

    return sd;
    }

    Thanks,
    Alon
  • I am closing the thread, if issue still exist please open a new thread and add a link to this one for reference