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.

THREADPARAMS * pSocket;
pSocket->m_sServerSocket.Accept(m_sClientSocket);

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.