Server Manager and the Unix socket server
In order to be able to use stream_socket_client()
to connect to a socket server, we need to first create the server with stream_socket_server()
. The principle is identical to what we saw in the previous chapter when explaining the example with a simple HTTP server, made just using stream_socket_server()
, stream_socket_accept()
, and StreamSelectLoop
:
class ServerManager extends Command { // ... private $statusSubject; private $servers = []; protected function execute($input, $output) { // ... @unlink($this->unixSocketFile); $address = "unix://" . $this->unixSocketFile; $server = stream_socket_server($address, $errno, $errMsg); stream_set_blocking($server, 0); $this->loop->addReadStream($server, function() use ($server) { $client = stream_socket_accept($server); $server = new GameServerStreamEndpoint($client,...