CC3200用TCP方式收发信息, 建立TCP连接如下:
sAddr.sin_family = SL_AF_INET;
sAddr.sin_port = sl_Htons((unsigned short)g_uiPortNum);
sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp);
iAddrSize = sizeof(SlSockAddrIn_t);
// creating a TCP socket
iSockID1 = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if( iSockID1 < 0 )
{
ASSERT_ON_ERROR(TCP_CLIENT_FAILED);
}
// connecting to TCP server
iStatus = sl_Connect(iSockID1, ( SlSockAddr_t *)&sAddr, iAddrSize);
if( iStatus < 0 )
{
// error
ASSERT_ON_ERROR(sl_Close(iSockID1));
ASSERT_ON_ERROR(TCP_CLIENT_FAILED);
}
while(1)
{
//下面是向服务器发送串口信息,这是可以的。
if (g_ucUARTBuffer[0]!=0)//broadcast new command by mDNS
{
// sending packet
iStatus = sl_Send(iSockID1, g_ucUARTBuffer, sizeof(g_ucUARTBuffer), 0 );
if(iStatus<=0)
{
ASSERT_ON_ERROR(sl_Close(iSockID1));
ASSERT_ON_ERROR(TCP_CLIENT_FAILED);
}
memset(g_ucUARTBuffer, 0, sizeof(g_ucUARTBuffer));
}
//下面是接收服务器的数据,是不可以的
iStatus = sl_Recv(iSockID1,g_cBsdbuf,sizeof(g_cBsdbuf),0);
if(iStatus > 0)
{
UART_PRINT(">>>%s\r\n", g_cBsdbuf);
}
else
{
ASSERT_ON_ERROR(sl_Close(iSockID1));
ASSERT_ON_ERROR(TCP_CLIENT_FAILED);
}
}
并且出现很奇怪的问题就是,当加上红色代码的时候,原先发送串口数据就不成立 了。求解答。。。。
Yonghua Pan:
你运行SDK里面的例程运行的通吗?