WTF!
What it is Im doing, Its a server, and im trying to limit the clients to 10,
And what I want is a value to increment when a client connects, and the value the decrement when the client disconnects.
so heres the basic code:
- for(;;){
-
sin_size = sizeof their_addr;
-
clientsocket = accept(serversocket, (struct sockaddr *)&their_addr, &sin_size);
-
if(childrun < CHILDS){
-
if(!fork()){
-
childrun++;
-
{message.write("Client-"); message.write(childrun); message.write(": connected.<br>\n");}
-
for(;;)
-
{
-
// the cient stuff
-
}
-
-
close(clientsocket);
-
childrun--;
-
message.write("::Client Disconnected.<br>\n");
-
exit(0);
-
}
-
close(clientsocket);
-
}
-
}
-
And the output is:
Client connected:--
::Sending welcome message: Sent
Server: Ping
Client-1: Pong.
Client-1: This is the first client
Client connected: --
::Sending welcome message: Sent.
Server: Ping
Client-1: Pong.
Client-1: <-- ??? this is the second client