Documente Academic
Documente Profesional
Documente Cultură
php
$port = 10000;
while (true) {
// create a copy, so $clients doesn't get modified by socket_select()
$read = $clients;
// get a list of all the clients that have data to be read from
// if there are no clients with data, go to next iteration
if (socket_select($read, $write = NULL, $except = NULL, 0) < 1)
continue;
socket_getpeername($newsock, $ip);
echo "New client connected: {$ip}\n";
// loop through all the clients that have data to read from
foreach ($read as $read_sock) {
// read until newline or 1024 bytes
// socket_read while show errors when the client is disconnected, so
silence the error messages
$data = @socket_read($read_sock, 1024);