PHP code example of gos / websocket-client

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

    

gos / websocket-client example snippets



use Gos\Component\WebSocketClient\Wamp\Client;

$client = new Client('127.0.0.1', 8080);


use Gos\Component\WebSocketClient\Wamp\ClientFactory;

$factory = new ClientFactory(['host' => '127.0.0.1', 'port' => 8080]);
$client = $factory->createConnection();


use Gos\Component\WebSocketClient\Wamp\ClientFactory;

$factory = new ClientFactory(['host' => '127.0.0.1', 'port' => 8080]);
$client = $factory->createConnection();

$sessionId = $client->connect();

// Establish a prefix on server
$client->prefix('calc', 'http://example.com/simple/calc#');

// You can send an arbitrary number of arguments
$client->call('calc', 12, 14, 15);

$data = [0, 1, 2];

// Or an array
$client->call('calc', $data);

$exclude = [$sessionId]; // No sense in sending the payload to ourselves
$eligible = []; // List of other clients ids that are eligible to receive this payload

$client->publish('topic', '', $exclude, $eligible);

// Publish an event
$client->event('topic', '');
$client->disconnect();