From: Slackin on
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
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
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
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