Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone point me to sample code that actually uses CAsyncSocket where the server's OnAccept notification Detaches the socket, re-Attaches it in another thread?

Currently, my prototype has to destroy the listener socket and re-create it in order for it to be able to MyServerCAsyncSocket::OnAccept a second MyClientCAsyncSocket::Connect-ion from the client. That is not supposed to be how it works. The listener socket is supposed to remain open waiting for the next data from the client.

But there doesn't seem to be any working sample code from which I could determine what I am doing wrong in my code. Hence, my request.

What I have tried:

I have tried Detach and Attach. After Detach, I set the m_hSocket = NULL which MSDN prescribes, but does an ASSERT( m_hSocket == INVALID_SOCKET ) which is -1, not NULL.
Posted
Updated 19-Aug-16 10:48am
Comments
Richard MacCutchan 17-Aug-16 12:58pm    
Can someone point me to
What is wrong with using Google?
rtischer8277 18-Aug-16 10:15am    
Very funny. But I'm serious. C++ MFC's CAsyncSocket doesn't seem to have any users, even in the much lauded MFC legacy code arena. If so, I'd at least like to hear about it. See my StackOverflow posting: "No server OnAccept notification when doing client Connect a second time".

For simplicity I would use always a new socket.

As the ASSERT tells: set
C++
m_hSocket = INVALID_SOCKET;

when done. If you use some third party code => stick to its rules.

Check out this sample project.
 
Share this answer
 
Igor Tandetnik in the Visual Studio C++ forum pointed a poster to a sample program and that showed a fully functioning CAsyncSocket. This program, MFCSOCS.EXE, may be ftp downloaded from http://ftplike.com (search for MFCSOCS.EXE). This is the only sample program that showed in one easy client/server program how CAsyncSocket works which in effect implicitly shows the true state diagram of its notifications (OnReceive, OnConnect, OnSend, OnOutOfBandData and OnClose) and their verbs (Receive, Connect, Accept, Send and Close). These relationships, I contend, cannot be deduced from MSDN's reference material. Unless, of course, you already know what the relationships are which is what MS advises at the outset.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900