Programming with threads and sockets

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

OK, see the sticky in this forum at top and let me know you think :)
[Mostly retired moderator, still check in to clean up some stuff]
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT »

Well, I think that will help a lot, though I was beginnig to get the functionnement, with this tutorial it will be far faster. Thx a lot, since I'm kind of late :oops: .Now I'll try to include it in my code :D . However, I hope that pSocket->Accept(false) will really prevent the GUI from freezing...

As for threads, I made a project just to test stuffs about it, and as I assumed that I could have several connexions at the same time, I made a table of threads...My idea was to affect them with a variable named status, which takes values FREE or BUSY. Then when I got a connexion, I would browse the thread table in order to find a thread with the free status...

Well actually I did this because of a problem of variable (name), but I guess that as with the server, each connexion makes a socketBase object which is independant from the server, there will be no problem of variable and a table of threads will be useless. At least I hope so... Gonna check this right now.

Thx again, I'm sure your tutorial will help a lot of people.
Thomas Stegemann
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Sep 15, 2005 11:19 am

Thead

Post by Thomas Stegemann »

Hi!

I try to code a client-server-app and want create a multi-thead-server.

There should exist a handling thread for every connection.
(called Worker)

Isn't it possible to create a waiting thread (Worker:public wxThread)
which handles socket events using a handler (Handler:public wxEvtHandler) created inside the thread?


This is the some code of a connection thread entry:

wxThread::ExitCode Worker::Entry(void)
{
Handler handler(this->m_socket);
while(handler->IsHandling())
{
if (this->TestDestroy())
return NULL;
this->Sleep(1); // no 100% usage of cpu
}
return NULL;
}

(Socket was param of the thead and is already accepted by the server...)

My handler reacts only on the socket loss, but sockt input is also defined in the handler. Hmmm....
Any ideas?! More questions?!

Thx,
Thomas Stegemann
Post Reply