服务器端监听客户端,用非阻塞模式,当accept一个连接后,就开一个线程,这个线程只是用于接收客户端发过来的数据!
但我这里的问题是,客户端在一个connect操作后,并没有send任何数据给服务器,而服务器用于接收客户端的数据的线程却可以接受到有数据,而且可以不停的接收,就算客户端关了也会收到有数据。
但这个recv返回的是SOCKET_ERROR,请教高手,为什么会出现这种情况?

解决方案 »

  1.   

    这个正常啊。你是非阻塞模式,recv返回SOCKET_ERROR,就是recv出错了,你用GetLastError检查一下错误码。
      

  2.   

    你把recv的socket设置成非阻塞了吧
      

  3.   

    是这样的:
    newSocket=accept(m_sockListen,(struct sockaddr *)&from,&len);
    这个accept操作中m_sockListen是被设置成非阻塞的,而newSocket我并没有把它设置成阻塞或是非阻塞模式。我想也是这里出点问题。帮我看年看
      

  4.   

    你把相关代码贴出来,怀疑你的recv调用有问题。
      

  5.   

    The accept function extracts the first connection on the queue of pending connections on socket s. It then creates and returns a handle to the new socket. The newly created socket is the socket that will handle the actual connection; it has the same properties as socket s, including the asynchronous events registered with the WSAAsyncSelect or WSAEventSelect functions.
      

  6.   

    to lsgt() 
    也就是说accept返回的套接节和accept的第一个参数里的套接字具用同样的属性,那我怎么把一个套接字设置成阻塞模式??