Hello,
I'm running an accept() in a while loop after configuring a server. After a successful connection, I receive data and close the connection. It works well, but after ~10-13 connections, the CC3000 seems to stop responding. It appears as though the accept() functions is non-blocking from when I run the program with the debugger. When the CC3000 stops responding, the Tiva gets stuck in the hci_event_handler function by the if statement "if (tSLInformation.usEventOrDataReceived != 0)"
This makes me think that something is wrong with the CC3000 because the usEventOrDataReceived is set when the SPI event handler receives communication from the CC3000.
Here is the code that I run on startup. I'm guessing that I am not closing my connections appropriately and causing the CC3000 to go out of whack. I've been building off of the basic_wifi_application in TivaWare.
Thanks,
Jackson
void serverconfig (void)
{
//
//socket locals
//
int32_t i32Check = 0;
//
//bind locals
//
uint32_t ui32Port = 0;
int8_t i8Check = 0;
//
//Listen/accept locals
//
uint8_t closeSuccess = 0;
socklen_t socketlength=sizeof(sockaddr);
char pui8Data[]="helloworld";
uint32_t ui32DataLength=strlen(pui8Data);
int32_t CommandCheck;
//
// Reset global socket type holder.
//
g_ui32SocketType = 0;
//
// Wait for DHCP process to finish. If you are using a static IP address
// please delete the wait for DHCP event - ulCC3000DHCP
//
while((g_ui32CC3000DHCP == 0) || (g_ui32CC3000Connected == 0))
{
hci_unsolicited_event_handler();
ROM_SysCtlDelay(1000);
}
//
// Open socket.
//
i32Check = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
//
// Set global variable that holds type of socket.
//
g_ui32SocketType = IPPROTO_TCP;
//
// Inform user of the socket being opened.
//
UARTprintf(" Socket is of type TCP\n");
//
// Error checking.
//
if(i32Check >= 0)
{
UARTprintf(" Socket Handle is '%d'\n",i32Check);
g_ui32Socket = i32Check;
}
else
{
UARTprintf(" Socket Function returned an error."
" Socket not opened. Error code %d.\n",i32Check);
g_ui32SocketType = 0;
return;
}
//
// Family is Always AF_INET on CC3000
//
g_tSocketAddr.sa_family = AF_INET;
//
// Set the port to bind the socket to.
//
ui32Port = DEFAULT_SERVER_PORT;
g_tSocketAddr.sa_data[0] = (ui32Port & 0xFF00) >> 8;
g_tSocketAddr.sa_data[1] = (ui32Port & 0x00FF) >> 0;
//
// Set IP to 0.0.0.0
//
memset (&g_tSocketAddr.sa_data[2], 0, 4);
//
// Low Level API call
//
i8Check = bind(g_ui32Socket, &g_tSocketAddr, sizeof(sockaddr));
if(i8Check == 0)
{
UARTprintf(" Bind Successful to port %d, 0x%x\n",
(g_tSocketAddr.sa_data[0] << 8) + g_tSocketAddr.sa_data[1],
(g_tSocketAddr.sa_data[0] << 8) + g_tSocketAddr.sa_data[1]);
//
// Set global flag variable to indicate the socket has been bound.
//
g_ui32BindFlag = 0;
}
else
{
UARTprintf(" Bind Failed. bind() returned code '%d'\n",i8Check);
//
// Set global flag variable to indicate the socket is not bound.
//
g_ui32BindFlag = SENTINEL_EMPTY;
}
//
//Listen for connection on TCP stream socket.
//
if(listen(g_ui32Socket,1))
{
UARTprintf(" Listen Failed.");
}
else
{
UARTprintf(" Listening.");
}
//
//Assign new socket for receiving info from client. Original socket
//is still listening.
//
//
//Loop over accept() function to address new clients.
//
while(1)
{
hci_unsolicited_event_handler();
i32Check=accept(g_ui32Socket, &g_tSocketAddr, &socketlength);
//
//If connection with client is successful, read data in and close
//socket immediately to wait for new connection.
//
if(i32Check>0)
{
UARTprintf(" Socket Handle is '%d'\n",i32Check);
g_ui32Socket_client1=i32Check;
receiveData();
CommandCheck=CmdLineProcess(g_pui8CC3000_Rx_Buffer);
if(CommandCheck == CMDLINE_BAD_CMD)
{
noCommand();
}
closeSuccess = closesocket(g_ui32Socket_client1);
//
// Error checking.
//
if(COMMAND_SUCCESS == closeSuccess)
{
UARTprintf(" Socket '%d' closed successfully.\n",g_ui32Socket_client1);
g_ui32Socket_client1 = SENTINEL_EMPTY;
}
else
{
UARTprintf(" Socket close Failed.\n");
g_ui32Socket_client1 = SENTINEL_EMPTY;
}
}
}
return(0);
}