int BsdTcpClient(unsigned short usPort)
{SlSockAddrIn_t sAddr;
SlSockAddrIn_t sLocalAddr;
int iCounter;
int iAddrSize;
int iSockID;
int iStatus;
int iNewSockID;
long lLoopCount = 0;
long lNonBlocking = 1;
int iTestBufLen;
// filling the buffer
for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++)
{
g_cBsdBuf[iCounter] = (char)(iCounter % 10);
}
iTestBufLen = BUF_SIZE;
//filling the TCP server socket address
sLocalAddr.sin_family = SL_AF_INET;
sLocalAddr.sin_port = sl_Htons((unsigned short)usPort);
sLocalAddr.sin_addr.s_addr = 0;
// creating a TCP socket
iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if( iSockID < 0 )
{
// error
ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);
}
iAddrSize = sizeof(SlSockAddrIn_t);
// binding the TCP socket to the TCP server address
iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize);
if( iStatus < 0 )
{
// error
sl_Close(iSockID);
ASSERT_ON_ERROR(BIND_ERROR);
}
// putting the socket for listening to the incoming TCP connection
iStatus = sl_Listen(iSockID, 0);
if( iStatus < 0 )
{
sl_Close(iSockID);
ASSERT_ON_ERROR(LISTEN_ERROR);
}
// setting socket option to make the socket as non blocking
iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING,
&lNonBlocking, sizeof(lNonBlocking));
if( iStatus < 0 )
{
sl_Close(iSockID);
ASSERT_ON_ERROR(SOCKET_OPT_ERROR);
}
iNewSockID = SL_EAGAIN;
// waiting for an incoming TCP connection
while( iNewSockID < 0 )
{
// accepts a connection form a TCP client, if there is any
// otherwise returns SL_EAGAIN
iNewSockID = sl_Accept(iSockID, ( struct SlSockAddr_t *)&sAddr,
(SlSocklen_t*)&iAddrSize);
if( iNewSockID == SL_EAGAIN )
{
MAP_UtilsDelay(10000);
}
else if( iNewSockID < 0 )
{
// error
sl_Close(iNewSockID);
sl_Close(iSockID);
ASSERT_ON_ERROR(ACCEPT_ERROR);
}
}
iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING,
&lNonBlocking, sizeof(lNonBlocking));
if( iStatus < 0 )
{
sl_Close(iSockID);
ASSERT_ON_ERROR(SOCKET_OPT_ERROR);
}
//wireless UART 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 cRxBuf[100];
int iStatus;
SlSockAddrIn_t sAddr;
int iAddrSize;
UART_PRINT("Start Receiving...");
while(1)
{iStatus = sl_Recv(iSockID, cRxBuf, 100, 0);
if(iStatus > 0)
{ if(cRxBuf[iStatus-2] == 0x0d)
{
cRxBuf[iStatus]=0;
UART_PRINT("\r\n接收:");
Message(cRxBuf);
UART_PRINT("Receive Successfully");
}
else break;
}
}
return(iStatus);
}
以上是我的主要函数部分 测试的时候 能连接上开发板 但是发送数据收不到 一直卡在sl_recv 这是为什么呢?