Implementing a WebSocket client
To implement a WebSocket client, we're going to use another PHP library called ratchet/pawl
:
$ composer require ratchet/pawl 0.2.2
The client will read input from php://stdin
and send it via WebSocket to the server. It'll also watch for any incoming messages and print them to the console:
// GameClient.php use function Ratchet\Client\connect; class GameClient extends Command { protected function configure() { $this->setName('chat-client'); $this->addArgument('port', InputArgument::REQUIRED); $this->addArgument('address', InputArgument::OPTIONAL, '', '127.0.0.1'); } protected function execute($input, $output) { $port = $input->getArgument('port'); $address = $input->getArgument('address'); $stdin = fopen('php://stdin', 'r'); $loop = new StreamSelectLoop(); connect('ws://' . $address . ':'...