1. Go to this page and download the library: Download hoa/socket library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hoa / socket example snippets
$server = new Hoa\Socket\Server('tcp://127.0.0.1:4242');
$server->connectAndWait();
while (true) {
foreach ($server->select() as $node) {
$line = $server->readLine();
if (empty($line)) {
$server->disconnect();
continue;
}
echo '< ', $line, "\n";
$server->writeLine(strtoupper($line));
}
}
$client = new Hoa\Socket\Client('tcp://127.0.0.1:4242');
$client->connect();
$readline = new Hoa\Console\Readline\Readline();
while (true) {
$line = $readline->readLine('> ');
if ('quit' === $line) {
break;
}
$client->writeLine($line);
echo '< ', $client->readLine(), "\n";
}