rec = recv(client.m_socket,(char *) recemsg,2000,0);rec的值为零,但是recemsg的值不为零的?

解决方案 »

  1.   

    用WSAGetLastError()看看返回值
      

  2.   

    不行啊.WSAGetLastError()的返回值是0啊!?
      

  3.   

    1.if recv return 0 then the connection is graceful closed by peer.
    2.Please check the value of recemsg before call recv.if the data changed after call recv then you received data already otherwise none data was received.
      

  4.   

    而且recemsg的确是接收到了字符啊
      

  5.   

    send 对了吗?(char *) recemsg
    改成
    char recvmsg[1024]
    后面两个值再改一下
      

  6.   

    If no error occurs, recv returns the number of bytes received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
      

  7.   

    connection has been gracefully是服务器关了客户的socket还是怎样啊?
      

  8.   

    对方调用了closesocket
    并设置了so_linger选项
      

  9.   

    可以告诉我so_linger的选项的作用吗?
      

  10.   

    SO_LINGER 
    设置或获取 SO_LINGER 选项的值. 其参数为 linger 结构. 
    struct linger {
        int   l_onoff;    /* 延时状态(打开/关闭) */
        int   l_linger;   /* 延时多长时间 */
    };
    如果选择此选项, close(2) 或 shutdown(2) 将等到所有套接字里排队的消息成功发送或到达延迟时间后才会返回. 否则, 调用将立即返回. 而 closing 操作将在后台进行. 如果套接字是 exit(2), 的一部分关闭时, 它总是在后台延迟进行的.