From: Slackin on 10 Apr 2010 20:02 I'm migrating of CAsyncSocket to socket API. And I would like to know: How to replace the OnAccept method? The code I have is the following: /**SocketServer.h **/ public: virtual void OnAccept( int nErrorCode ); /**SocketServer.cpp**/ //Implemetation void CSocketEscucha::OnAccept(int nErrorCode) { if (nErrorCode == 0) { OTRACE("Connected"); m_pFrame->ToConnect(); } }
From: Slackin on 10 Apr 2010 20:18 On 10 abr, 20:02, Slackin <pedroosorio...(a)gmail.com> wrote: > I'm migrating of CAsyncSocket to socket API. > And I would like to know: How to replace the OnAccept method? > > The code I have is the following: > > /**SocketServer.h **/ > > public: > virtual void OnAccept( int nErrorCode ); > > /**SocketServer.cpp**/ > //Implemetation > void CSocketEscucha::OnAccept(int nErrorCode) > { > if (nErrorCode == 0) > { > OTRACE("Connected"); > m_pFrame->ToConnect(); > } > > } I know that: socket API CAsyncSocket ---------------- ---------------------- Accept() CAsyncScoket::Accept() Bind() CAsyncSocket::Bind() Create() CAsyncSocket::Create() ??? CAsyncSocket::OnAccept() but CAsyncSocket::OnAccept() == ?
From: Geoff on 11 Apr 2010 00:52 On Sat, 10 Apr 2010 17:02:24 -0700 (PDT), Slackin <pedroosorio777(a)gmail.com> wrote: >I'm migrating of CAsyncSocket to socket API. >And I would like to know: How to replace the OnAccept method? > >The code I have is the following: > >/**SocketServer.h **/ > >public: > virtual void OnAccept( int nErrorCode ); > > >/**SocketServer.cpp**/ >//Implemetation >void CSocketEscucha::OnAccept(int nErrorCode) >{ > if (nErrorCode == 0) > { > OTRACE("Connected"); > m_pFrame->ToConnect(); > } >} There is no equivalent. You will not receive a message on accept. You say you are unwrapping CAsyncSocket API, therefore your app will loop the accept call until it receives a valid handle. The return value from accept() will indicate the status, depending on the result you will receive a handle on the socket and then you must loop on a recv() call until you receive 0 bytes or WSAECONNRESET error code.
From: Hector Santos on 11 Apr 2010 07:38 In sync mode, you need to switch to async using ioctlsocket() and use the select() command using the correct parameters depending if you are a server or client for the call you make: server --> accept() client --> connect() so yo do: ioctlsock(); // switch to async mode accept() or connect() // these call return immediately select() // test for events but you need to prepare select correctly, watch for the read parameter for server, write parameter for client. -- Slackin wrote: > On 10 abr, 20:02, Slackin <pedroosorio...(a)gmail.com> wrote: >> I'm migrating of CAsyncSocket to socket API. >> And I would like to know: How to replace the OnAccept method? >> >> The code I have is the following: >> >> /**SocketServer.h **/ >> >> public: >> virtual void OnAccept( int nErrorCode ); >> >> /**SocketServer.cpp**/ >> //Implemetation >> void CSocketEscucha::OnAccept(int nErrorCode) >> { >> if (nErrorCode == 0) >> { >> OTRACE("Connected"); >> m_pFrame->ToConnect(); >> } >> >> } > > I know that: > > socket API CAsyncSocket > ---------------- ---------------------- > > Accept() CAsyncScoket::Accept() > Bind() CAsyncSocket::Bind() > Create() CAsyncSocket::Create() > ??? CAsyncSocket::OnAccept() > > but CAsyncSocket::OnAccept() == ? -- HLS
|
Pages: 1 Prev: Displaying Animated Cursor Next: http Internet Programming using MFC |