微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI WIFI设计交流 > CC3200 TCP client 接收问题

CC3200 TCP client 接收问题

时间:10-02 整理:3721RD 点击:

TI工程师:

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

如果是非阻塞应该不会有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);

}

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

int BsdTcpClient(unsigned short usPort)
{
    SlSockAddrIn_t  sAddr;
    int             iAddrSize;
    int             iSockID;
    int             iStatus;

    //filling the TCP server socket address
    sAddr.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 socket
    iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
    if( iSockID < 0 )
    {
        ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);
    }

    // connecting to TCP server
    iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize);
    if( iStatus < 0 )
    {
        // error
        sl_Close(iSockID);
        ASSERT_ON_ERROR(CONNECT_ERROR);
    }

    //setting nonblokcking mode
    long 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 transfer
    iStatus = WuartTransfer(UARTA0_BASE, iSockID);
    if(iStatus < 0)
    {
    	UART_PRINT("WUART Transfer failed\n\r");
    }
 

    iStatus = sl_Close(iSockID);
    //closing the socket after sending 1000 packets
    ASSERT_ON_ERROR(iStatus);

    return SUCCESS;
}
int WuartTransfer(unsigned long ulBase, int iSockID) {
	char cTxBuf[100];
	char cRxBuf[100];
	char cGetChar;
	int  iStatus;
	int  iCounter = 0;

	while(1)
	{
		//UART receive characters
		cGetChar = MAP_UARTCharGetNonBlocking(ulBase);
		if(cGetChar != 0xff)
		{//Save received characterscTxBuf[iCounter++] = cGetChar;//Enter or Escif((cGetChar == 0x0d) || (cGetChar == 0x1b)){	//Send TCP packets
     			        iStatus = sl_Send(iSockID, cTxBuf, iCounter, 0);	if(iStatus <= 0)	{//errors handleASSERT_ON_ERROR(sl_Close(iSockID));	 	UART_PRINT("Sending data failed\n\r");break;	}	//enter	if(cGetChar == 0x0d)	{iCounter = 0;	}	//Esc, exit the loop	elsebreak;

}

		}
		//Receive TCP packets
		iStatus = 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 loopelse	break;
		}
	}
	return(iStatus);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top