PHP code example of sowe / websocketio

1. Go to this page and download the library: Download sowe/websocketio 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/ */

    

sowe / websocketio example snippets

use Sowe\WebSocketIO\Server;
use Sowe\WebSocketIO\Client;

rt', function() {
    echo "Server started!" . PHP_EOL;
});
$server->on('stop', function() {
    echo "Server stopped!" . PHP_EOL;
});
$server->on('connection', function(Client $client) {
    $client->on('disconnect', function() {
        echo "Client " . $client->getId() . " disconnected" . PHP_EOL;
    });
    $client->on('error', function($error) {
        echo "Client " . $client->getId() . " error: " . $error . PHP_EOL;
    });

    echo "New client connected " . $client->getId() . " from IP " . $client->getAddress() . PHP_EOL;
});