2012-06-02 18:46:34 +02:00
|
|
|
<?php
|
|
|
|
$tcp = uv_tcp_init();
|
|
|
|
|
|
|
|
uv_tcp_bind($tcp, uv_ip4_addr('0.0.0.0',79));
|
|
|
|
$users = array(
|
|
|
|
array(
|
|
|
|
"username" => "chobie",
|
|
|
|
"name" => "Shuhei Tanuma",
|
|
|
|
"twitter" => "chobi_e",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
function pad($str)
|
|
|
|
{
|
|
|
|
return str_pad($str, 20, ' ',STR_PAD_RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
uv_listen($tcp,100, function($server) use ($users){
|
|
|
|
$client = uv_tcp_init();
|
|
|
|
uv_accept($server, $client);
|
2012-06-30 15:15:29 +02:00
|
|
|
uv_read_start($client, function($socket, $buffer, $nread) use ($users){
|
2012-06-02 18:46:34 +02:00
|
|
|
$buffer = str_replace("/W","",$buffer);
|
|
|
|
if ($buffer == "\r\n") {
|
|
|
|
$data = "";
|
|
|
|
$keys = array("Login","Name","Twitter");
|
|
|
|
$data .= join("",array_map("pad",$keys)) . "\r\n";
|
|
|
|
foreach($users as $user) {
|
|
|
|
$data .= join("", array_map("pad",array_values($user))) . "\r\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
uv_write($socket, $data, function($stat, $client){
|
|
|
|
uv_close($client);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var_dump($buffer);
|
|
|
|
uv_close($socket);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
uv_run();
|