示例#1
0
文件: index.php 项目: drpain/ditaio
function server($port)
{
    echo "SERVER LISTENING ON: {$port}" . PHP_EOL . PHP_EOL;
    $socket = @stream_socket_server("tcp://localhost:{$port}", $errNo, $errStr);
    if (!$socket) {
        throw new Exception($errStr, $errNo);
    }
    stream_set_blocking($socket, 0);
    $socket = new CoSocket($socket);
    while (true) {
        (yield newTask(handleClient((yield $socket->accept()))));
    }
}
示例#2
0
function server($port)
{
    echo "Starting server at port {$port}...\n";
    $socket = stream_socket_server("tcp://localhost:{$port}", $errNo, $errStr);
    if (!$socket) {
        throw new Exception($errStr, $errNo);
    }
    stream_set_blocking($socket, 0);
    /*     while (true) {
            echo "server wait for read\n";
            var_dump($socket);
            yield waitForRead($socket);
            $clientSocket = stream_socket_accept($socket, 0);
            yield newTask(handleClient($clientSocket));
        } */
    $socket = new CoSocket($socket);
    while (true) {
        echo "server before newTask\n";
        (yield newTask(handleClient((yield $socket->accept()))));
    }
}
示例#3
0
function server($port)
{
    echo "Starting server at port {$port}...\n";
    $socket = @stream_socket_server("tcp://0:{$port}", $errNo, $errStr);
    if (!$socket) {
        throw new Exception($errStr, $errNo);
    }
    stream_set_blocking($socket, 0);
    $socket = new CoSocket($socket);
    while (true) {
        (yield newTask(handleClient((yield $socket->accept()))));
    }
}