Código PHP:
#!/usr/bin/php -q
<?
error_reporting(E_ALL);
ob_implicit_flush();
$address = '127.0.0.1';
$port = 9999;
if (($master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
print ("[WON] socket_create() failed, reason: " . socket_strerror($master) . "\n");
}
socket_set_option($master, SOL_SOCKET,SO_REUSEADDR, 1);
if (($ret = socket_bind($master, $address, $port)) < 0) {
print ("[WON] socket_bind() failed, reason: " . socket_strerror($ret) . "\n");
}
if (($ret = socket_listen($master, 5)) < 0) {
print ("[WON] socket_listen() failed, reason: " . socket_strerror($ret) . "\n");
}
$read_sockets = array($master);
print ("[WON] Servidor iniciado en ".$address.":".$port." para ".$read_sockets."!\n");
while (true) {
$changed_sockets = $read_sockets;
$num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL);
foreach($changed_sockets as $socket) {
if ($socket == $master) {
if (($client = socket_accept($master)) < 0) {
print ("[WON] socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n");
continue;
} else {
array_push($read_sockets, $client);
}
} else {
$bytes = socket_recv($socket, $buffer0, 2048, 0);
$buffer = explode(', ', $buffer0);
if ($bytes == 0) {
$index = array_search($socket, $read_sockets);
unset($read_sockets[$index]);
socket_close($socket);
}else{
@include($buffer[0].".php");
socket_write($client, "a"); //AQUI ES, PERO NO ENVIA
}
}
}
}
?>
Código PHP:
socket_write($client, $buffer0);
Código PHP:
$buffer0 = "a";
socket_write($client, $buffer0);
Gracias