iocp客户端已经connect了,但 getpeername 没值。需要设置哪个地方?

解决方案 »

  1.   

    WSAGetLastError()看看错误返回到那里客户端是阻塞方式,应该没问题。
    如果是非阻塞方式,需要真正连接成功后调用
      

  2.   

    DWORD val = 1;
    int error = setsockopt( socket, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, (char *)&val, sizeof(DWORD)); SO_UPDATE_CONNECT_CONTEXT 
    This option is used with the ConnectEx, WSAConnectByList, and WSAConnectByName functions. This option updates the properties of the socket after the connection is established. This option should be set if the getpeername, getsockname, getsockopt, setsockopt, or shutdown functions are to be used on the connected socket. 
      

  3.   

    connect了后还需要发送第一条消息吧
      

  4.   

    如果是connectex则无需再发第一条消息