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.

CC3100MOD: TCP multiple client connections

Part Number: CC3100MOD
Other Parts Discussed in Thread: CC3100

Hi All,

I want to do TCP multiple client connection on One TCP server. One client and server connection i did. It's working.

How can i make it as multiple.?

If you have any example please attach. 

Regards,

Aravinth

  • Hi,

    Please search for tutorial for BSD sockets, for example:
    - TCP server for multiple clients using select: www.binarytides.com/.../
    - TCP server for multiple clients using threads/tasks: www.binarytides.com/.../

    Jan
  • Hi Hnz,
    Thanks for your reply. This is linux example. Do you have any RTOS example for CC3100.

    Regards,
    Aravinth
  • Hi,

    It is not important that example is for Linux. Important this is that this examples use BSD sockets.

    Jan
  • Hi Jan,
    I tried from your example. It's receiving some packet and it goes to StackOverFlow (vApplicationStackOverflowHook)

    Regards,
    Aravinth
  • Hi,

    You need properly implement memory/thread handling according your platform. This examples are not "ready to use" at all platforms. This examples you can use as base for your code. In this examples is well described how works BSD sockets in TCP server for multiple clients.

    Jan
  • Hi Jan,

    This is my code. I'm facing StackOverFlow (vApplicationStackOverflowHook) error. Can you tell any this you found as wrong on this code.

    #define STACKSIZE_WiFiTASK       256

    #define STACKSIZE_WiFiRevTASK       128

    static _i32 WIFI_TcpServerInit(_u16 Port)

    {

      LocalAddr.sin_family = SL_AF_INET;

       LocalAddr.sin_port = sl_Htons((_u16)Port);

       LocalAddr.sin_addr.s_addr = 0;

       SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);

       if( SockID < 0 )

       {

        UARTprintf(" [TCP Server] Create socket Error \n\r");

           ASSERT_ON_ERROR(SockID);

       }

       UARTprintf(" [TCP Server] Create socket success \n\r");

       AddrSize = sizeof(SlSockAddrIn_t);

       Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);

       if( Status < 0 )

       {

           sl_Close(SockID);

           UARTprintf(" [TCP Server] Socket address assignment Error \n\r");

           ASSERT_ON_ERROR(Status);

       }

       UARTprintf(" [TCP Server] Socket address assignment Success \n\r");

       Status = sl_Listen(SockID, 7);

       if( Status < 0 )

       {

           sl_Close(SockID);

           UARTprintf(" [TCP Server] Listen Error \n\r");

           ASSERT_ON_ERROR(Status);

       }

       UARTprintf(" [TCP Server] Listen Success \n\r");

       while(1)

       {

        newSockID = sl_Accept(SockID, ( struct SlSockAddr_t *)&Addr,

                                 (SlSocklen_t*)&AddrSize);

       if( newSockID < 0 )

       {

           sl_Close(SockID);

           UARTprintf(" [TCP Server] Accept connection Error \n\r");

           ASSERT_ON_ERROR(newSockID);

       }

       UARTprintf(" [TCP Server] Accept connection Success \n\r");

       UARTprintf("Connection Count = %d \r\n",++count);

       TCPServer_RevDataTaskInit(newSockID);

       }

    //*****************************************************************************

    //

    // This is CC3100 WiFi TCPServer_RevDataTask

    //

    //*****************************************************************************

    static void

    TCPServer_RevDataTask(void *pvParameters)

    {

       _i16          Status = 0;

       _u16 count = 0;

       _i16          recvSize = 0;

       UARTprintf(" [TCP Server] pvParameters = %d \n\r",pvParameters);

       while (1)

        {

            recvSize = BUF_SIZE;

            do

            {

            Status = WIFI_TcpServerRevData((uint32_t)pvParameters, &(data_buf[BUF_SIZE - recvSize]), recvSize, 0);

                if( Status <= 0 )

                {

                WIFI_TcpServerClose((uint32_t)pvParameters);

                UARTprintf(" [TCP Server] Data recv Error \n\r");

                   // wifi_connection = false;

                   // ASSERT_ON_ERROR(TCP_RECV_ERROR);

                }

                  recvSize -= Status;

            }while(recvSize > 0);

            UARTprintf("[TCP Server] pvParameters = %d Count = %d \r\n", pvParameters, ++count);

        }

    }

    //*****************************************************************************

    //

    // Initializes the TCPServer_RevDataTaskInittask.

    //

    //*****************************************************************************

    uint32_t

    TCPServer_RevDataTaskInit(_i16 TCPSockID)

    {

       //

       // Create the WiFi task.

       //

       if(xTaskCreate(TCPServer_RevDataTask, (const portCHAR *)"TCPServer_RevDataTask",

        STACKSIZE_WiFiRevTASK, (void *)TCPSockID,

                      tskIDLE_PRIORITY + PRIORITY_WiFi_TASK, NULL) != pdTRUE)

       {

           return(1);

       }

     

    Regards,

    Aravinth