Problems with CAsyncSocket in a workerthread
Cyrill Stachniss -- Cyrill.Stachniss@ArcoMedia.de Tuesday, March 25, 1997 Environment: VC++ 4.2-flat, NT 4.0 Hello ! I'm writing a chatserver and want to give any incomming client (Java) one thread (workerthread) for reading and writing data. But I have problems to get the OnReceive-notification in this thread. If I don't start the workerthread and create the socket (CAsyncSocket) in the mainthread I get the OnReceive-notification. --- The thread starts here... AfxBeginThread(ClientIOThread, (LPVOID) socket.Detach() ) ...and calls this "Workerthread-Function": UINT ClientIOThread( LPVOID pParam ) { CClientSocket* pSocket = new CClientSocket(); pSocket->Attach( (SOCKET) pParam, FD_CLOSE | FD_READ | FD_WRITE );
Sreekant Sreedharan -- sreekant@india.deneb.com Friday, March 28, 1997 Cyrill Stachniss wrote: > > Environment: VC++ 4.2-flat, NT 4.0 > > Hello ! > I'm writing a chatserver and want to give any incomming > client (Java) one thread (workerthread) for reading and > writing data. > But I have problems to get the OnReceive-notification in > this thread. If I don't start the workerthread and create > the socket (CAsyncSocket) in the mainthread I get the > OnReceive-notification. > > --- > The thread starts here... > AfxBeginThread(ClientIOThread, (LPVOID) socket.Detach() ) > > ...and calls this "Workerthread-Function": > UINT ClientIOThread( LPVOID pParam ) > { > CClientSocket* pSocket = new CClientSocket(); > pSocket->Attach( (SOCKET) pParam, FD_CLOSE | FD_READ | FD_WRITE ); I'm not too sure about the solution myself, but I can give you a hint. What I see here is that you are creating a one socket the main thread and another in the child thread. Now the problem is that a CAsyncSocket object internally uses a hidden CWnd to receive your messages. This is how you have a `Acync' mode of transfer. I am sure it will be clear if you have gone through the SDK winchat example. Now you may notice that the CWnd Object can receive notification only through one thread, which may be why you are having this problem. -- - From Sreekant Sreedharan
Become an MFC-L member | Вернуться в корень Архива |