SFML community forums
Help => General => Topic started by: Regen on August 07, 2008, 02:11:08 pm
-
I have a server-client application. The server is suppsoed to identify the client connecting and then start the acording thread for the client, after that it should continue to lissen for other clients. This is a part of the code:
ClientIncomming() is returning the client-socket to the global variable Sock.
do{
Client = ClientIncomming(4567);
Client.Receive(Pack);
Pack >> Type;
if(Type == "Boss" && !BossThread){
sf::Thread Boss(&Boss);
Boss.Launch();
}
else if(Type == "Shooter" && !ShooterThread){
sf::Thread Shooter(&Shooter);
Shooter.Launch();
}
else if(Type != "Boss" || Type != "Shooter")
std::cout << "Undefined Client tried to connect, rejected" << std::endl;
}while(1);
The thing is...the threads dont really act like threads, they act lika normal functions...
anyone have any idea? please ask me if you want some other part of the code.
-
Your threads are stopped when your sf::Thread instances are destroyed.
-
They are destroyed when you leave the scope of an 'if' or 'else if' statement, because they are local instances.
-
sf::Thread Boss(&Boss);
sf::Thread Shooter(&Shooter);
do{
Client = ClientIncomming(4567);
Client.Receive(Pack);
Pack >> Type;
if(Type == "Boss" && !BossThread){
Boss.Launch();
}
else if(Type == "Shooter" && !ShooterThread){
Shooter.Launch();
}
else if(Type != "Boss" || Type != "Shooter")
std::cout << "Undefined Client tried to connect, rejected" << std::endl;
}while(1);
-
ahhhh, thanks a lot! works now:)