[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CAsyncSocket - OnAccept method NOT CALLED

Posted on 2002-06-17
7
Medium Priority
?
1,173 Views
Last Modified: 2012-05-04
If anybody knows, what could cause that

  the OnAccept method of the CAsyncSocket class is not called,

please help me!

My code is as follows:

/******************************************************/

CMySocket::CMySocket()
{
  if ( !Create( 80, SOCK_STREAM, FD_ACCEPT ) ) throw CMyException( 1, GetMyLastError() );
  if ( !Listen() ) throw CMyException( 2, GetMyLastError() );
}

CMySocket::~CMySocket()
{
  Close();
}

#if 0
BEGIN_MESSAGE_MAP(CMySocket, CAsyncSocket)
     //{{AFX_MSG_MAP(CMySocket)
     //}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif     // 0

void CMySocket::OnAccept( int nErrorCode )
{
  // HERE IS A BREAKPOINT
  AfxMessageBox( "REQUEST" );
 
  CAsyncSocket::OnAccept(nErrorCode);
}

char *CMySocket::GetMyLastError()
{
  switch ( GetLastError() )
  {
    case WSAEFAULT: return "WSAEFAULT";
    case WSANOTINITIALISED: return "WSANOTINITIALISED";
    case WSAENETDOWN: return "WSAENETDOWN";
    case WSAEINPROGRESS: return "WSAEINPROGRESS";
    default: return "???";
  }
}

/******************************************************/

Note: When I try to connect to the socket from Internet Explorer (watching the comunication on TCPView - something like dynamically refreshing netstat), the socket is listening and then connection is established, but - is I've told - the OnAccept method is never called :-(
Why???

Regards
Aegressy
0
Comment
Question by:aegressy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 7086195
There is nothing wrong with the code that you have presented - it works in my simple app - how have you initialised the sockets I am assuming you used AfxSocketInit in you InitInstance method of your CWinApp derived class

You also might have had better response if you posted this to the MFC forum
0
 

Author Comment

by:aegressy
ID: 7087884
ShaunWilde,

  thanks for your response, yes, I've done the AfxSocketInit(), I can send you my code if you want - or if you tried this, would you be so kind and send me your program? (If so, my mail address is: aegressy@yahoo.com)

  A very similar code works fine in HTTPSVR sample from the MSDN lib. on the same machine, compiled in the same environment... And after two days I simply don't know what is wrong with this.

Thanks a lot!
Aegressy
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 7088411
please send your code shaun_wilde@hotmail.com
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Accepted Solution

by:
ShaunWilde earned 300 total points
ID: 7089303
ahh - you don't have a message pump - the MFC socket classes are based on WINSOCK and require messages to be pumped in order for them to work

I changed your code slightly to be like this and OnAccept now gets called

try
{
  p_myServer = new CMyServer();

/*
               char cmd = 0;
               while ( ( cmd != 'q' ) & ( cmd != 'Q' ) )
               {
                   
               }
               */

               MSG msg;
               while (GetMessage(&msg,NULL,0,0))
                    DispatchMessage(&msg);
          }
0
 

Author Comment

by:aegressy
ID: 7090061
Thanks a lot!
You are absolutely totally right :-)

I didn't want to create a GUI interface for this applicatoin and I didn't know, that Console (!) Win32 applications don't have their message pumps. (I thought that one is attached to the window, that the process runs in but I now realize, that this is a nonsence...)

I would like to ask you, if there is another way how to add a message pump and not have to loop in the main function?

Thank you once more.
Regards
Aegressy
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 7090285
you can always spawn it off in it its own thread and control that from the main thread

you can create a GUI-less MFC app by having a hidden main window

an ATL exe server (or service) can have MFC support (there are MS-KB articles on how to do this) and no GUI - if you want to make one from the project wizard
0
 

Author Comment

by:aegressy
ID: 7090488
I've nothing more to say, than: thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question