Hello! I am using the TM4C123GH6PM board and testing the TI RTOS sample: "tcpEchoCC3000".
Normal single receive / echo data is working fine, but I would like to continuously receive / echo data to a client.
On my computer a have made a c# application that connects (ip-address and port) to the CC3000, sends a specified data string and receives the echo back. When I try to send data multiple times, the board won't receive any more than the first package.
Any suggestions? Are there any reasons for why the sample code should not allow this?
* ======== echoFxn ========
* Prints IP address and echos messages through TCP.
*
* Task for this function is created statically. See the project's .cfg file.
*/
Void echoFxn(UArg arg0, UArg arg1)
{
Int nbytes;
Int status;
Int clientfd;
Bool flag = TRUE;
UChar spNum[2] = {0};
ULong currButton;
ULong prevButton = 0;
Long lSocket;
WiFi_Params params;
WiFi_Handle handle;
sockaddr_in sLocalAddr;
sockaddr_in client_addr;
socklen_t addrlen = sizeof(client_addr);
/* Turn LED off. It will be used as a connection indicator */
GPIO_write(Board_LED0, Board_LED_OFF);
/* Open WiFi */
WiFi_Params_init(¶ms);
params.bitRate = 4000000;
handle = WiFi_open(Board_WIFI, Board_SPI_CC3000, asynchCallback, ¶ms);
/* Mask out all non-required events */
wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE | HCI_EVNT_WLAN_UNSOL_INIT |
HCI_EVNT_WLAN_ASYNC_PING_REPORT);
/* Check service pack version */
nvmem_read_sp_version(spNum);
if ((spNum[0] != PACKAGEID) || (spNum[1] != PACKAGEBLDNUM)) {
System_printf("You are using service pack version %d.%d! This example "
"is recommended for use\nwith %d.%d. Run the TI-RTOS "
"CC3000 Patcher example to get this version.\n\n",
spNum[0], spNum[1], PACKAGEID, PACKAGEBLDNUM);
System_flush();
}
/*
* Wait for the WiFi device to connect to an AP. If a profile for the AP in
* use has not been stored yet, press Board_BUTTON0 to put the CC3000 in
* Smart Config mode.
*/
while ((deviceConnected != TRUE) || (dhcpComplete != TRUE)) {
/*
* Start Smart Config if a button is pressed. This could be done with
* GPIO interrupts, but for simplicity polling is used to check the
* button.
*/
currButton = GPIO_read(Board_BUTTON0);
if((currButton == 0) && (prevButton != 0))
{
smartConfigFxn();
}
prevButton = currButton;
Task_sleep(50);
}
System_printf("CC3000 has connected to AP and acquired an IP address.\n");
/* Print IP address */
System_printf("IP Address: %d.%d.%d.%d\n", ipRecvd[0], ipRecvd[1],
ipRecvd[2], ipRecvd[3]);
System_flush();
/* Echo data using TCP */
lSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (lSocket == -1) {
System_printf("socket failed\n");
Task_exit();
}
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
sLocalAddr.sin_family = AF_INET;
sLocalAddr.sin_addr.s_addr = htonl(0);
sLocalAddr.sin_port = htons(TCPPORT);
status = bind(lSocket, (const sockaddr*)&sLocalAddr, sizeof(sLocalAddr));
if (status < 0) {
System_printf("bind failed\n");
closesocket(lSocket);
Task_exit();
}
if (listen(lSocket, 0) == -1){
System_printf("listen failed\n");
closesocket(lSocket);
Task_exit();
}
do {
/* Wait for incoming request */
clientfd = accept(lSocket, (sockaddr*)&client_addr, &addrlen);
Task_sleep(300);
} while (clientfd == SOC_IN_PROGRESS);
if (clientfd == -1) {
System_printf("accept failed\n");
closesocket(lSocket);
Task_exit();
}
/* Loop while we receive data */
while (flag) {
nbytes = recv(clientfd, buffer, TCPPACKETSIZE, 0);
int i;
for (i = 0; i < nbytes; i++)
{
temp[i] = buffer[i];
}
i=0;
// if (nbytes > 0) {
// /* Echo the data back */
// send(clientfd, buffer, nbytes, 0 );
// }
// else {
// flag = FALSE;
// }
flag = FALSE;
}