0

Hi guyz. I am making a client-server application uysing CAnsySocket. A little history may help you assist. I made the application and was working just okay but the problem was that two client app. could not connect to the server. It always crashed. A viable solution to that was making a multi threaded server. Now, i have set worker threads for accepting the connection (For listening it is using the main thread). Below is the accepting code:

OnAccept()
{
    THREADPARAMS * pSocket; // THREADPARAMS is a structure defined in .h
    AfxBeginThread(AcceptFunc, pSocket);
}
UNIT AcceptFunc(LPARAM pParam)
{
    THREADPARAMS * pSocket;
    pSocket->m_sServerSocket.Accept(m_sClientSocket);
}
//in my .h
typedef struct THREADPARAMS
{
    CMySocket m_sServerSocket, m_sClientSocket;
}

the error is in line 9. The code is compiling just okay but when the client tries to connect the server crashes. Now, when i debug, it us taking me to line 9. Things to do with the parameters. I have trapped an error that i would expect if the client cannot locate the server but since that error is not popping, the server is listenning just okay, just the accepting part. Please assist me.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by dandan
0
THREADPARAMS * pSocket;
pSocket->m_sServerSocket.Accept(m_sClientSocket);

pSocket is not initialized. You need to assign a valid value first.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.