Override of CAsyncSocket::OnAccept fails 
Author Message
 Override of CAsyncSocket::OnAccept fails

Hi

Stupidity cannot be ruled out but I'm having a problem with deriving my
own class from CAsyncSocket.  My overriding functions for OnAccept,
Onconnect etc aren't being called.

I've compiled the example code, chatsrvr and chatclnt, from MSDN CD and
this works making me think I've missed something obvious.  Has anyone
had a similar problem??.

I've derived my class using the ClassWizard in VC++ 6 on NT4
workstation.

Thanks

Sam



Sun, 26 Jan 2003 03:00:00 GMT  
 Override of CAsyncSocket::OnAccept fails



Quote:
> Stupidity cannot be ruled out but I'm having a problem with deriving my
> own class from CAsyncSocket.  My overriding functions for OnAccept,
> Onconnect etc aren't being called.

It's pretty hard to guess what might be wrong without a peek
at the code.  However, I don't really want to see the entire
project posted here.

Can you post the part of the header file that shows the
derivation?  And the code that shows your OnAccept and
OnConnect?  And the code where you create the instance
of your socket?

--
Dan Evens
Standard disclaimers etc. No spam please.



Sun, 26 Jan 2003 03:00:00 GMT  
 Override of CAsyncSocket::OnAccept fails

Thanks for replying Dan

Here are the code fragments you wanted to see.

Class definition
================

// Overrides
public:
        int LServerAccept(LClientSocket &endPoint);
        int LServerListen(int queue);

        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(LServerSocket)
        public:
        virtual void OnAccept(int nErrorCode);
        //}}AFX_VIRTUAL

        // Generated message map functions
        //{{AFX_MSG(LServerSocket)
                // NOTE - the ClassWizard will add and remove member
functions here.
        //}}AFX_MSG

Override function
=================

void LServerSocket::OnAccept(int nErrorCode)
{
cout << "OnAccept" << endl;
CAsyncSocket::OnAccept(nErrorCode);
return;

Quote:
}

And where I create the socket from initialising the socket API
================

// Initialise the socket API
if(AfxSocketInit(NULL) == 0)
{
cerr << "Failed to initialise the socket API\n" << endl;
nRetCode = 1;

Quote:
}

else
{
    try
    {
    // Create the server socket
    server = new LServerSocket(9999);
    cout << "Created server socket   " << server->ipAddress << "," <<
server->portNumber << endl;

     // Set it listening
     server->LServerListen(2);
     cout << "Listening....." << endl;

     ....
     }

Any help will be much appreciated

Thanks

Sam



Sun, 26 Jan 2003 03:00:00 GMT  
 Override of CAsyncSocket::OnAccept fails

Quote:

> Hi

> Stupidity cannot be ruled out but I'm having a problem with deriving my
> own class from CAsyncSocket.  My overriding functions for OnAccept,
> Onconnect etc aren't being called.

> I've compiled the example code, chatsrvr and chatclnt, from MSDN CD and
> this works making me think I've missed something obvious.  Has anyone
> had a similar problem??.

> I've derived my class using the ClassWizard in VC++ 6 on NT4
> workstation.

> Thanks

> Sam

When you call the listening socket Create function do you pass the FD_ACCEPT
flag?
The flags tell it what callbacks you want.

  Create(nPort, SOCK_STREAM, FD_ACCEPT);

--
Scott McPhillips [VC++ MVP]



Sun, 26 Jan 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. no message to CAsyncSocket::OnAccept

2. Does CAsyncSocket::OnAccept support concurrency?

3. CAsyncSocket::OnAccept gets called twice, Why???

4. Overriding CAsyncSocket OnReceive doesn't work in Win32 Console Application

5. CAsyncSocket and function Overrides ...

6. CAsyncSocket::OnReceive not overridden now, OK earlier project

7. why i can connect server by using CSocket , and it failed when using CAsyncSocket

8. CAsyncSocket unusable after failed connect

9. !!!!! Please help CAsyncSocket & Assert Fail

10. Simple CAsyncSocket - Why failed

11. Why i can connect server using CSocket , but fail by using CAsyncSocket

12. OnAccept w/o Accept

 

 
Powered by phpBB® Forum Software