Todor Atanasov
2013-07-02 06:13:07 UTC
Hi Guys,
Just before I start, I know CSocket are advised not to be used, but I need CSocketFile in order to use CArchive, so I have no other option for now.
What I'm doing is I have one thread that listens for incoming connection, then accepts it and creates a new thread to handle the connection. I am doing everything there has to be done ( at least I think I am :D). So I detach the socket, and attach it in the new thread. But there is the problem, the OnReceive() is never called. The thread is UI, created like this:
CSocket soc;
Accept(soc);
CConnectThread* pThread = (CConnectThread*)AfxBeginThread(RUNTIME_CLASS(CConnectThread),THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
if (!pThread) {
soc.Close();
return;
}
pThread->m_hSocket = soc.Detach();
pThread->ResumeThread();
CSocket::OnAccept(nErrorCode);
The SOCKET is attached in the InitInstance() and I also have a Run() which runs until a flag is set to stop it.
In the OnReceive all I have is
{
TRACE("TCP->WORKS\n");
}
I can't call SCocket::Receive() because it is saying that I can't use a non-static member function.
Any thoughts?
Just before I start, I know CSocket are advised not to be used, but I need CSocketFile in order to use CArchive, so I have no other option for now.
What I'm doing is I have one thread that listens for incoming connection, then accepts it and creates a new thread to handle the connection. I am doing everything there has to be done ( at least I think I am :D). So I detach the socket, and attach it in the new thread. But there is the problem, the OnReceive() is never called. The thread is UI, created like this:
CSocket soc;
Accept(soc);
CConnectThread* pThread = (CConnectThread*)AfxBeginThread(RUNTIME_CLASS(CConnectThread),THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
if (!pThread) {
soc.Close();
return;
}
pThread->m_hSocket = soc.Detach();
pThread->ResumeThread();
CSocket::OnAccept(nErrorCode);
The SOCKET is attached in the InitInstance() and I also have a Run() which runs until a flag is set to stop it.
In the OnReceive all I have is
{
TRACE("TCP->WORKS\n");
}
I can't call SCocket::Receive() because it is saying that I can't use a non-static member function.
Any thoughts?