Hello!
I'm creating a OOP PHP Socket server, that needs to accept multiple simultaneous client connections and reply a msg back to them if they send a certain message to the server.
I have the following code:
while (true){
echo "looping";
$thisClient = socket_accept($tSocket);
$Clients->newClient($thisClient);
$Clients->CheckForNewMessages();
sleep(5);
}
$Clients->CheckForNewMessages();
checks for new messages trying to be written:
public function CheckForNewMessages(){
foreach ($this->clientObjs as $thisClient){
$clientObject = $thisClient['Object'];
$cID = $clientObject->getID();
$thisChildSocket = $clientObject->getClientSocket();
$theMSG = socket_read($thisChildSocket, 1024);
Logging::log("INFO", "$cID sent $theMSG");
}
}
But i cannot find or figure out how to detect if a new client connects and if a new client is trying to write messages to the server.
How could i do this?