Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic example for running a subscriber client #1

Open
sabit opened this issue Jul 6, 2019 · 0 comments
Open

Basic example for running a subscriber client #1

sabit opened this issue Jul 6, 2019 · 0 comments

Comments

@sabit
Copy link

sabit commented Jul 6, 2019

I would like to use the WAMP client as a standalone script. Could you be kind enough to share a basic example? I am trying to create a standalone php client to subscribe to messages from CLI.

This is my code:

<?php
require_once __DIR__ . "/vendor/autoload.php";

use IPub\WebSocketsWAMPClient\Client\Client;
use IPub\WebSocketsWAMPClient\Client\Configuration;
use React\EventLoop;

$loop = React\EventLoop\Factory::create();
$config = new Configuration('127.0.0.1', 8282);
$wc = new Client($loop, $config);

try{

    $wc->connect();
    $wc->subscribe('MYTOPIC');
    
}catch(IPub\WebSocketsWAMPClient\Exceptions\ConnectionException $e){
    echo "Failed to connect";
    exit();
}

echo 'Running';
$wc->getLoop()->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant