BlackSun
December 16th, 2004, 04:22 AM
So, this is what my app is supposed to do...
It's a regular client-server thingy, with one server and at most 4 other people connecting. This I've planned to do with the app running in one window and then a thread doing all the netowrking things, which worked quite nice, until I came up with this great idea, that the server should also be running a client, that way, there should be no special cases, the server just does it's thing and the client does his things. This would mean 3 threads in the server and 2 in the clients.
Of course, I don't get it to work, as soon as the client is started the server seems to shut down, why is that ?
heres my code ....
CWinThread *m_pServerThread;
CWinThread *m_pClientThread;
// The serverthread is started like this ...
m_pServerThread = AfxBeginThread(Server, this);
UINT CTestDlg::Server(LPVOID pParam)
{
// Get a link to the main window ...
CKommTestDlg* pDlg = (CTestDlg*) pParam;
// Get the sockets in order ...
// Some socket stuff going on...
// Start the own client ...
Clientstart(pDlg);
// Accept connections from the own client
// Do the accept stuff ....
MessageBox("I'm here !!"); // This never shows ...
while (true)
{
// Some really good stuff here ...
}
}
// The clientstart starts the client like this
m_pClientThread = AfxBeginThread(Client, this);
UINT CTestDlg::Client(LPVOID pParam)
{
// Link to main window
CKommTestDlg* pDlg = (CKommTestDlg*) pParam;
// Make all the connections, connect to server
while (true)
{
// I do get in here ...
}
return 0;
}
So, is it something with the way I start the threads?, cause If I run the client and server by themselves it works, so the networking stuff should be fine.
Or can't I have a program sonnect to itself? (network question maybe, nut you gurus seem to know it all :) )
It's a regular client-server thingy, with one server and at most 4 other people connecting. This I've planned to do with the app running in one window and then a thread doing all the netowrking things, which worked quite nice, until I came up with this great idea, that the server should also be running a client, that way, there should be no special cases, the server just does it's thing and the client does his things. This would mean 3 threads in the server and 2 in the clients.
Of course, I don't get it to work, as soon as the client is started the server seems to shut down, why is that ?
heres my code ....
CWinThread *m_pServerThread;
CWinThread *m_pClientThread;
// The serverthread is started like this ...
m_pServerThread = AfxBeginThread(Server, this);
UINT CTestDlg::Server(LPVOID pParam)
{
// Get a link to the main window ...
CKommTestDlg* pDlg = (CTestDlg*) pParam;
// Get the sockets in order ...
// Some socket stuff going on...
// Start the own client ...
Clientstart(pDlg);
// Accept connections from the own client
// Do the accept stuff ....
MessageBox("I'm here !!"); // This never shows ...
while (true)
{
// Some really good stuff here ...
}
}
// The clientstart starts the client like this
m_pClientThread = AfxBeginThread(Client, this);
UINT CTestDlg::Client(LPVOID pParam)
{
// Link to main window
CKommTestDlg* pDlg = (CKommTestDlg*) pParam;
// Make all the connections, connect to server
while (true)
{
// I do get in here ...
}
return 0;
}
So, is it something with the way I start the threads?, cause If I run the client and server by themselves it works, so the networking stuff should be fine.
Or can't I have a program sonnect to itself? (network question maybe, nut you gurus seem to know it all :) )