我在创建一个TCP连接时,明明已经连上了,为什么client端的connect还是返回
SOCKET_ERROR?请问这可能是什么原因?谢谢!

解决方案 »

  1.   

    On a blocking socket, the return value indicates success or failure of the connection attempt.With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. 
      

  2.   

    GetLastError来看看是什么错误代码
      

  3.   

    是WSAEWOULDBLOCK 错误
     还有,怎么把accept设为非阻塞?谢谢
      

  4.   

    TO 楼主:
    明明已经连上了!你是怎么知道连上了的? connect 不是报错吗?
      

  5.   

    to up:
         我试着进行收发信息,已经可行了
      

  6.   

    你用的是异步套接字,即异步socket,改成同步就ok了
      

  7.   

    你是不是不停的在connect?
    可能是超时,用getlasterror()看看吧
      

  8.   

    我写一个很简单的程序,来测试socket的工作,
    服务器已经在listen了
    但client端在connect时,总是返回10061错误(WSAGetLastError),用Error look看是:
    不能做任何连接,因为目标机器积极地拒绝它。是什么意思?
      

  9.   

    这些是简单问题啦。看看msdn的例子,看看socket的构造和初始化,ip地址,端口号等等。自己应该搞定了的。
      

  10.   

    是啊,本来是应该可以搞定的了,但他就是不工作呀
    气得我干瞪眼,也没有办法了
    不是我不想把它搞定,也不是不想去看一看究竟是怎么回事,可无论如何搞,就是不正确
    那还有什么办法?
    再说了,msdn上的示例我找不到