1
CAsyncSocket::OnConnect()
virtual void OnConnect( int nErrorCode );ResCalled by the framework to notify this connecting socket that its connection attempt is completed, whether successfully or in error
函数被framework调用,表明正在连接的socket的连接意图已经完成,而不论连接
是不是成功上面的翻译理解是不是对的呢?
我的理解是这样的:当调用了CAsyncSocket::Connect()函数后,在未来未知的时间里,framework将自动调用CAsyncSocket::OnConnect()这样的理解对吗?
我测试了一下,设很多的断点,发现程序的流程不是很一致。2
CAsyncSocket::OnReceive
virtual void OnReceive( int nErrorCode );
Called by the framework to notify this socket that there is data in the buffer that can be retrieved by calling the Receive member function. For more information, see the articleWindows Sockets: Socket Notifications in Visual C++ Programmer's Guide.被framework调用,表明socket有data在buffer中,buffer可以通过调用Receive member function来得到。理解:如果buffer中有data 的话,那么framework会调用CAsyncSocket::OnReceive。这样的理解是不是对的呢?

解决方案 »

  1.   

    ResCalled by the framework to notify this connecting socket that its connection attempt is completed, whether successfully or in error.Important   In CSocket, the OnConnect notification function is never called. For connections, you simply call Connect, which will return when the connection is completed (either successfully or in error). How connection notifications are handled is an MFC implementation detail. 
      

  2.   

    Client端发出连接请求,并且Server同意Accept后,
    Client端触发了OnConnect事件
      

  3.   

    waitingforyou(中国男人) ( ) 信誉:100 Client端发出连接请求,并且Server同意Accept后你的意思是说:“连接上了就调用OnConnect”吗?
      

  4.   

    TO : qing_li73(bluemoon) (:
    不会吧,但是我感觉一般都是成功才调用的,你能否举个例子你见到的连不上仍调用?
      

  5.   

    Have a try, debug whether it can be called when the connection attempt is completed in error.I just posted the res of MSDN 
      

  6.   

    BOOL Connect( LPCTSTR lpszHostAddress, UINT nHostPort );BOOL Connect( const SOCKADDR* lpSockAddr, int nSockAddrLen );Return Value
    那,Connect的返回值有什么意义呢?不懂!
      

  7.   

    我对waitingforyou(中国男人)得回贴有质疑,根据MSDN,CONNECT操作结束后就CALLBACK ONCONNECT, 操作结果作为参数传递。CAsyncSocket::OnConnect()又返回值吗?找了半天也没见到你得BOOL Connect( LPCTSTR lpszHostAddress, UINT nHostPort );
      

  8.   

    http://expert.csdn.net/Expert/topic/1235/1235060.xml?temp=9.058779E-02
      

  9.   

    我自己总结一下,然后结帐:
    在Connect()后,系统会自动调用OnConnect()函数Connect()的返回值在我看来确实没有什么意义。要判断是不是连接成功,在OnConnect()里面判断;CMyAsyncSocket:;OnConnect(int nErrorCode)
    {
           if(nErrorCode == 0)            //连接成功
           {
           }
           
           else                          //连接不成功
           {
            }
    }就是这样的了
      

  10.   

    to  waitingforyou(中国男人) ( ) 信誉:100 Client端发出连接请求,并且Server同意Accept后,
    Client端触发了OnConnect事件
    我测试过的,即使没有server,只运行 client ,在connect()后,ONCONNECT()马上就被调用了。