TI中文支持网
TI专业的中文技术问题搜集分享网站

CC3200 TCP client 接收问题

TI工程师:

      我使用了两块CC3200进行TCP数据传输实验,其中一块作为服务器,另一块作为客户端,使用的是无阻塞的方式。为什么客户端调用sl_Recv( )函数接收数据时会有较长时间的延时,但服务器端就不会出现这种情况?并且为什么服务器连续给客户端发送几条数据,客户端接收时还会出现数据丢失的情况,同样的,服务器端却不会出现这种问题?

Yue TANG:

如果是非阻塞应该不会有delay, 你的代码是如何写的?

NonBlocking = 1; iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET,\ SL_SO_NONBLOCKING, \ &NonBlocking, sizeof(NonBlocking)); if( iStatus < 0 ) { // error ERR_PRINTS("Socket Setting Err"); ASSERT_ON_ERROR(sl_Close(iSockID)); ASSERT_ON_ERROR(TCP_CLIENT_FAILED); }

Yihong:

回复 Yue TANG:

以下是我客户端TCP部分的代码:

int BsdTcpClient(unsigned short usPort)
{SlSockAddrIn_tsAddr;intiAddrSize;intiSockID;intiStatus;//filling the TCP server socket addresssAddr.sin_family = SL_AF_INET;sAddr.sin_port = sl_Htons((unsigned short)usPort);sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulGatewayIP);iAddrSize = sizeof(SlSockAddrIn_t);// creating a TCP socketiSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);if( iSockID < 0 ){ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);}// connecting to TCP serveriStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize);if( iStatus < 0 ){// errorsl_Close(iSockID);ASSERT_ON_ERROR(CONNECT_ERROR);}//setting nonblokcking modelong lNonBlocking = 1;iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET,SL_SO_NONBLOCKING, &lNonBlocking, sizeof(lNonBlocking));if(iStatus < 0){sl_Close(iSockID);UART_PRINT("TCP Client failed\n\r");}//UART wireless transferiStatus = WuartTransfer(UARTA0_BASE, iSockID);if(iStatus < 0){UART_PRINT("WUART Transfer failed\n\r");}iStatus = sl_Close(iSockID);//closing the socket after sending 1000 packetsASSERT_ON_ERROR(iStatus);return SUCCESS;
}
int WuartTransfer(unsigned long ulBase, int iSockID) {char cTxBuf[100];char cRxBuf[100];char cGetChar;intiStatus;intiCounter = 0;while(1){//UART receive characterscGetChar = MAP_UARTCharGetNonBlocking(ulBase);if(cGetChar != 0xff){//Save received characterscTxBuf[iCounter++] = cGetChar;//Enter or Escif((cGetChar == 0x0d) || (cGetChar == 0x1b)){//Send TCP packetsiStatus = sl_Send(iSockID, cTxBuf, iCounter, 0);if(iStatus <= 0){//errors handleASSERT_ON_ERROR(sl_Close(iSockID));UART_PRINT("Sending data failed\n\r");break;}//enterif(cGetChar == 0x0d){iCounter = 0;}//Esc, exit the loopelsebreak;}}//Receive TCP packetsiStatus = sl_Recv(iSockID, cRxBuf, 100, 0);if(iStatus > 0){//Enterif(cRxBuf[iStatus-1] == 0x0d){//save"charaters ending"cRxBuf[iStatus]=0;Message(cRxBuf);}//Enter, exit the loopelsebreak;}}return(iStatus);
}

赞(0)
未经允许不得转载:TI中文支持网 » CC3200 TCP client 接收问题
分享到: 更多 (0)