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.

UDP not working after a while!!!



Hi 

I have wrote a server code for UDP communication in CC3000. 

It works fantastically fine for first 3 - 4 minutes but after that it wouldn't work at all. I cant receive data I send from the client.

Any help would be really appreciated. 

My CC3000 firmware version is 1.11

My App driver version is 4.14.7.13 

Here is my code UDP Server code

long socket_fd;
sockaddr from_address;
sockaddr my_addr;
unsigned char rx_buff[512];
memset(&rx_buff,0,sizeof(rx_buff));
memset(&from_address,0x00,sizeof(from_address));
volatile signed long ReturnValue = -1;
fd_set readsds;
timeval timeout;
timeout.tv_usec = 500;
SysCtlDelay(5000);

socket_fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);

if(socket_fd < 0)
{
             DispatcherUartSendPacket("socket failed to create",23);

             closesocket(socket_fd);

}

my_addr.sa_family = AF_INET;

my_addr.sa_data[0] = 0x13;

my_addr.sa_data[1] = 0x88;
my_addr.sa_data[2] = 0x0;
my_addr.sa_data[3] = 0x0;
my_addr.sa_data[4] = 0x0;
my_addr.sa_data[5] = 0x0;


int check_bind;
check_bind = bind(socket_fd,&my_addr,sizeof(my_addr));
if (check_bind < 0)

{

       DispatcherUartSendPacket("bind failed",11);

        closesocket(socket_fd);
}

while(1)
{

                 FD_ZERO(&readsds);
                 FD_SET(socket_fd, &readsds);
                 ReturnValue = select(socket_fd + 1, &readsds, NULL, NULL, &timeout);
                 DispatcherUartSendPacket ((unsigned char*)&ReturnValue, 1);

                 if ((ReturnValue != 0) && (ReturnValue != -1))
                 {
                               if (FD_ISSET(socket_fd,&readsds))
                               {
                                          ReturnValue = recvfrom(socket_fd, rx_buff, sizeof(rx_buff), 0, &from_address, (socklen_t *) sizeof(from_address));

                                          DispatcherUartSendPacket(&rx_buff[0], ReturnValue);
                                          SysCtlDelay(50);
                                          memset(&rx_buff[0],0,sizeof(rx_buff));


                                          if (ReturnValue < 0)
                                          {
                                                     closesocket(socket_fd);
                                                     DispatcherUartSendPacket("socket closed", 13);

                                          }

                                }

               }
}

  • Hi Shashank,

    Could you provide some details about the status of the program when it stops working? Is socket connected? Connected to AP? Crashed? ...?

    What is the throughput? Buffer size?


    Thanks,
    Aaron

  • Hi Aaron

    Thanks for responding.

    Here are some of the info u asked for

    When UDP stops working, the program gets stuck at the  while(1) of hci_event_handler(). CC3000 is not crashed as it is responding for ping properly.

    If I send data continuously through the buffer, the communication works fine. But when I stop, i.e during the idle state, UDP seizes to work after a while. Is there a timeout condition that closes the socket once it is met? If there is one, how do we handle it so that the communication is kept alive even during idle state? 

    Right now I couldn't find the status of the socket once the link is dead. M figuring it out. If there is a way, please let me know.

    For throughput, instead of giving the number, I would say I could receive all the bytes I sent without any drop. And finally I'm using 8 byte buffer for the communication link.

    Let  me know if you need any more info.

  • Hi Shashank,

    you can use the function netapp_timeout_values:

        unsigned long aucDHCP       = 14400;
        unsigned long aucARP        = 3600;
        unsigned long aucKeepalive  = 10;
        unsigned long aucInactivity = 0;

        netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity);

    The important parameter is the aucInactivity. Setting it to 0 disable the socket timeout.

    Best regards,

    Martin

  • Hi Martin

    Thanks for the immediate response.

    I shall give it a try n let you know the outcome asap.

    Regards,

    Shashank

  • Hi Martin

    Its working fine now :) The socket is not closed. Thanks for your support.

    Regards,

    Shashank