PHP code example of xp-forge / websockets
1. Go to this page and download the library: Download xp-forge/websockets 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/ */
xp-forge / websockets example snippets
use websocket\Listeners;
class Imitator extends Listeners {
public function serve($events) {
return [
'/echo' => function($conn, $payload) {
$conn->send('You said: '.$payload);
}
];
}
}
use util\cmd\Console;
use websocket\WebSocket;
$s= new WebSocket('ws://localhost:8081/echo';
$s->connect();
$s->send('Hello');
Console::writeLine('<<< ', $s->receive());