koryo22
December 23rd, 2007, 08:32 AM
Hi, I have a problem.
I'm trying to make a server applicattion with two threads.
1.- For writting messages to a client.
2.- For listening to messages sent by the client.
The CSocket is a member variable from my dialog initilized (the connection is established ... ) before the threads are created. When I use the socket in the thread for reading I have a problem with:
ASSERT(m_hSocket == INVALID_SOCKET || CAsyncSocket::FromHandle(m_hSocket) != NULL)
I have used the AfxSocketInit in the main thread and in the other two new threads but the problem still persists.
------ MAIN THREAD ----------------
HRESULT hr = ::CoInitialize(NULL);
AfxSocketInit(NULL);
CString szMssg;
m_sockConnection = new CBidirecSocket();
CBidirecSocket sockSrvr;
sockSrvr.Conectar(8686); // Creates our server socket
sockSrvr.Listen(); // Start listening for the client at PORT
sockSrvr.Accept(*(m_sockConnection)); // Use another CSocket to accept the connection
m_sockConnection->Init();
AfxBeginThread(ThreadWriteMessage, this);
----------- THREAD WRITE MESSAGE --------------
HRESULT hr = ::CoInitialize(NULL);
AfxSocketInit(NULL);
CMain* pServer = (CMain*) pVoid;
pServer->m_sockConnection->GetMssg(szMsg2); //<--- This function only calls to the read message of the CSocket. Here is where the problem occurs.
I hope someone can help me. Thanks very much!!!
I'm trying to make a server applicattion with two threads.
1.- For writting messages to a client.
2.- For listening to messages sent by the client.
The CSocket is a member variable from my dialog initilized (the connection is established ... ) before the threads are created. When I use the socket in the thread for reading I have a problem with:
ASSERT(m_hSocket == INVALID_SOCKET || CAsyncSocket::FromHandle(m_hSocket) != NULL)
I have used the AfxSocketInit in the main thread and in the other two new threads but the problem still persists.
------ MAIN THREAD ----------------
HRESULT hr = ::CoInitialize(NULL);
AfxSocketInit(NULL);
CString szMssg;
m_sockConnection = new CBidirecSocket();
CBidirecSocket sockSrvr;
sockSrvr.Conectar(8686); // Creates our server socket
sockSrvr.Listen(); // Start listening for the client at PORT
sockSrvr.Accept(*(m_sockConnection)); // Use another CSocket to accept the connection
m_sockConnection->Init();
AfxBeginThread(ThreadWriteMessage, this);
----------- THREAD WRITE MESSAGE --------------
HRESULT hr = ::CoInitialize(NULL);
AfxSocketInit(NULL);
CMain* pServer = (CMain*) pVoid;
pServer->m_sockConnection->GetMssg(szMsg2); //<--- This function only calls to the read message of the CSocket. Here is where the problem occurs.
I hope someone can help me. Thanks very much!!!