Ejemplo n.º 1
0
        echo $local_message->name . ":" . json_encode($request) . "\n";
        switch ($local_message->name) {
            case "testSimpleRequestResponse":
                if ($request["message"]["subject"] == "ping") {
                    return array("response" => "pong");
                } else {
                    if ($request["message"]["subject"] == "pong") {
                        return array("response" => "ping");
                    }
                }
                break;
            case "testSimpleRequestWithoutParameters":
                return array("response" => "no incoming parameters");
                break;
            case "testNotification":
                break;
            case "testRequestResponseException":
                if ($request["exception"]["cause"] == "callback") {
                    throw new AvroRemoteException(array("exception" => "raised on callback cause"));
                } else {
                    throw new AvroRemoteException("System exception");
                }
                break;
            default:
                throw new AvroRemoteException("Method unknown");
        }
    }
}
$server = new SocketServer('127.0.0.1', 1411, new TestProtocolResponder(AvroProtocol::parse($protocol)), true);
$server->start();
Ejemplo n.º 2
0
                });
                $sender->process = $process;
            }
        }
    }
    public $clientId = 0;
    public function onClientConnected(SocketServer $server, SocketClient $newClient)
    {
        $newClient->buffer = "";
        $newClient->process = false;
        $newClient->verified = false;
        $newClient->id = $this->clientId++;
    }
    public function onClientDisconnected(SocketServer $server, SocketClient $client)
    {
        if ($client->process) {
            $client->process->stop();
            $client->process = false;
        }
    }
    public function onLogMessage(SocketServer $server, $message)
    {
    }
}
global $params;
$params = @json_decode($_SERVER['argv'][2], true) ?: array();
$listener = new Listener();
$webSocket = new SocketServer(@$params['ip'] ?: '127.0.0.1');
$webSocket->addListener($listener);
$webSocket->start();