请问怎么知道sl_Recv函数接收到的数据是哪个端口的呢?
gaoyang9992006:
size = sl_Recv(iSockID,g_buffer,300,0);
而 iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
且 int iSockID;
char g_buffer[300]; //发送数据给指定的ip和端口号,只有一次 //执行过程 //1、新建连接 //2、发送数据、 //3、断开连接 void vSendOneDataWithIpPort(unsigned char *data,unsigned long len,unsigned long ip,unsigned long port) {SlSockAddrIn_tsAddr;intiAddrSize;intiSockID;intiStatus;int count = 0,size;//filling the TCP server socket address//使用的是socket//这个我忘了,基本是固定不变sAddr.sin_family = SL_AF_INET;//端口信息,sAddr.sin_port = sl_Htons((unsigned short)port);//ip信息sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)ip);iAddrSize = sizeof(SlSockAddrIn_t);// creating a TCP socket//创建一个tcp连接iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);if( iSockID < 0 ){UART_PRINT("Error:%s %d\r\n",__FUNCTION__,__LINE__);}// connecting to TCP server//连接到tcp的服务器,参数:socket的句柄,目的地址信息iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize);if( iStatus < 0 ){// erroriStatus = sl_Close(iSockID);if (iStatus < 0)UART_PRINT("Error:%s %d\r\n",__FUNCTION__,__LINE__);}//连接完成最好不要直接就发送数据,经我的测试是,马上发送数据可能会成功,但是数据却没有传过去delay();//发送数据,参数:socket的句柄,数据指针,数据长度,最后一个参数没有作用iStatus = sl_Send(iSockID, data, len, 0 );if( iStatus <= 0 ){// erroriStatus = sl_Close(iSockID);if (iStatus < 0)UART_PRINT("Error:%s %d\r\n",__FUNCTION__,__LINE__);}//接收数据。,参数:sockeet的句柄,缓冲区,缓冲器大小,返回的是接收的数据大小//请注意这个函数可能是阻塞的//阻塞的意思就是,会一直等到有数据才返回,或者有问题才返回size = sl_Recv(iSockID,g_buffer,300,0);transHeader =(SlTransceiverRxOverHead_t *)g_buffer;g_buffer[size] = 0;UART_PRINT("\r\nReceive:\r\n%s\r\n",g_buffer);//关闭连接iStatus = sl_Close(iSockID);if (iStatus < 0)UART_PRINT("Error:%s %d\r\n",__FUNCTION__,__LINE__);}