CAyncSocket::Detach Fails _AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL
-
hI I create four CAsynSocket Classes in four CwinThread classes When I first create them Socket (with notification events) bind ioctl, setsockopt. I follow the CASynSocket::Socket call to sockcore.cpp and
pState-> m_hSocketWindow
has a valid Hwnd Value. The context of the creation of sockets in the CwinApp after my main CFrameWnd has been created. I then start a conversation with the server (connect send and then receive). It is at a point that I would like to give the work over to a modeless dialog. this is where things go wrong. After getting a message from the server I try to do a detach which goes to
CAsyncSocket::AsyncSelect(long lEvent)
however at this point
_AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL
is NULL Since I was debugging this in release mode I never got the subsequent assert on this. First off in the documentation for CAsynSocket there is no mention that i need a Hwnd to process the class when I first did the CAsynSocket::Socket call with the event notification that I wanted to be informed on I did notice that
pState-> m_hSocketWindow
had a valid window When I first started using CAsyncSocket I know very little about TCPI/IP or OO at this point looking at Winscok API it has much more flexability so much so it seem I dont necessary need a valid Hwnd but a kernel object such as that from CreateEvent will do more so It seems if I want to pass notification to a different windows I just do another call to
WSAAsyncSelect
with a new HWND Still I am wondering why
pState-> m_hSocketWindow
went to NULL
-
hI I create four CAsynSocket Classes in four CwinThread classes When I first create them Socket (with notification events) bind ioctl, setsockopt. I follow the CASynSocket::Socket call to sockcore.cpp and
pState-> m_hSocketWindow
has a valid Hwnd Value. The context of the creation of sockets in the CwinApp after my main CFrameWnd has been created. I then start a conversation with the server (connect send and then receive). It is at a point that I would like to give the work over to a modeless dialog. this is where things go wrong. After getting a message from the server I try to do a detach which goes to
CAsyncSocket::AsyncSelect(long lEvent)
however at this point
_AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL
is NULL Since I was debugging this in release mode I never got the subsequent assert on this. First off in the documentation for CAsynSocket there is no mention that i need a Hwnd to process the class when I first did the CAsynSocket::Socket call with the event notification that I wanted to be informed on I did notice that
pState-> m_hSocketWindow
had a valid window When I first started using CAsyncSocket I know very little about TCPI/IP or OO at this point looking at Winscok API it has much more flexability so much so it seem I dont necessary need a valid Hwnd but a kernel object such as that from CreateEvent will do more so It seems if I want to pass notification to a different windows I just do another call to
WSAAsyncSelect
with a new HWND Still I am wondering why
pState-> m_hSocketWindow
went to NULL
It's probably not fair to send you down a different path, but many years ago I had similar problems and, having some spare time, I decided to make my own set of wrappers for Windows Sockets API. Over time it has grown into a quite capable set of objects that allow you to work with sockets just like you work with C++ streams. I've wrote a series of articles here and you can take a look see if they are of any help to you: - Windows Sockets Streams[^] - Windows Sockets Streams Part II - Multi-Threaded TCP Servers[^] - Windows Sockets Streams Part III - HTTP Server[^] Latest version of code can be downloaded from GitHub[^].
Mircea
-
hI I create four CAsynSocket Classes in four CwinThread classes When I first create them Socket (with notification events) bind ioctl, setsockopt. I follow the CASynSocket::Socket call to sockcore.cpp and
pState-> m_hSocketWindow
has a valid Hwnd Value. The context of the creation of sockets in the CwinApp after my main CFrameWnd has been created. I then start a conversation with the server (connect send and then receive). It is at a point that I would like to give the work over to a modeless dialog. this is where things go wrong. After getting a message from the server I try to do a detach which goes to
CAsyncSocket::AsyncSelect(long lEvent)
however at this point
_AFX_SOCK_THREAD_STATE* pState-> m_hSocketWindow == NULL
is NULL Since I was debugging this in release mode I never got the subsequent assert on this. First off in the documentation for CAsynSocket there is no mention that i need a Hwnd to process the class when I first did the CAsynSocket::Socket call with the event notification that I wanted to be informed on I did notice that
pState-> m_hSocketWindow
had a valid window When I first started using CAsyncSocket I know very little about TCPI/IP or OO at this point looking at Winscok API it has much more flexability so much so it seem I dont necessary need a valid Hwnd but a kernel object such as that from CreateEvent will do more so It seems if I want to pass notification to a different windows I just do another call to
WSAAsyncSelect
with a new HWND Still I am wondering why
pState-> m_hSocketWindow
went to NULL
I'd recommend you to check out this great Joe Newcomer's essay: [A Rewrite of KB192570: An MFC Asynchronous Socket Example Done Right](http://www.flounder.com/kb192570.htm)
-
It's probably not fair to send you down a different path, but many years ago I had similar problems and, having some spare time, I decided to make my own set of wrappers for Windows Sockets API. Over time it has grown into a quite capable set of objects that allow you to work with sockets just like you work with C++ streams. I've wrote a series of articles here and you can take a look see if they are of any help to you: - Windows Sockets Streams[^] - Windows Sockets Streams Part II - Multi-Threaded TCP Servers[^] - Windows Sockets Streams Part III - HTTP Server[^] Latest version of code can be downloaded from GitHub[^].
Mircea
-
I'd recommend you to check out this great Joe Newcomer's essay: [A Rewrite of KB192570: An MFC Asynchronous Socket Example Done Right](http://www.flounder.com/kb192570.htm)
He has a detach on the server side more so before any conversation gets going My scenario involves the main windows looks if anyone wants to start a conversation with the server if I see it happens a conversation with the server is initiated I want to pass off that socket to a mode less dialog Thanks