This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100发送数据失败怎么回事?

Other Parts Discussed in Thread: CC3100

我是用CC3100座位STA模式连上路由器,然后创建server等待cilent建立连接,CC3100在有cilent连上就往这个socket发送5个字节的数据,但总是发送失败,想请教下什么情况下会发送失败?

代码是在freertos上跑,发送代码如下:

  • 可以在仿真状态下查看一下,getsocketID是否正确的获取了正确的ID,

    sTestBufLen = BUF_SIZE;

    //filling the TCP server socket address
    sAddr.sin_family = SL_AF_INET;
    sAddr.sin_port = sl_Htons((unsigned short)usPort); //目的IP地址端口号
    sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); //目的IP地址IP_ADDR-手机上连接USR软件后配置TCP Server设置端口号并查看本机IP地址

    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); //<连接>目的IP地址及端口号
    if( iStatus < 0 )
    {
    // error
    sl_Close(iSockID);
    ASSERT_ON_ERROR(CONNECT_ERROR);
    }

    // sending multiple packets to the TCP server
    // sending packet
    iStatus = sl_Send(iSockID, g_cBsdBuf, sTestBufLen, 0 );

  • 就看sl_Send函数的参数是否正确了。只有错误的参数传递进去,才更容易返回错误的返回值。。

  • 从你的代码片段看不出线索,SockID和getSockID有什么差别?