cc3200工作在站点模式和多个终端同时连接到路由器组成局域网,多个终端发送tcp数据包到局域网分给3200的ip地址上,现在只能实现单个终端单独发送,请问如何才能让cc3200同时接收多个终端的数据呢? 谢谢指导
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;
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);
}
UART_PRINT("Wait for TCP Connection...\r\n");
// waiting for an incoming TCP connection
iNewSockID = SL_EAGAIN;
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);
}
}
UART_PRINT("Device Connected!\r\n");
char cRxBuf[BUF_SIZE];
while(1)
{
UART_PRINT("Start Receiving...\r\n");
//Receiving TCP package
iStatus = sl_Recv(iNewSockID, cRxBuf, iTestBufLen, 0); //正值表示接收字节数 P191
if(iStatus > 0)
{
cRxBuf[iStatus]=0;
UART_PRINT("\r\nReceive: ");
Message(cRxBuf);
UART_PRINT("\r\n");
} else break;
}
return SUCCESS;
}

