PHP code example of calcinai / bolt
1. Go to this page and download the library: Download calcinai/bolt 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/ */
calcinai / bolt example snippets
$loop = \React\EventLoop\Factory::create();
$dns_factory = new React\Dns\Resolver\Factory();
$resolver = $dns_factory->createCached('8.8.8.8', $loop);
$client = new \Calcinai\Bolt\Client('ws://127.0.0.1:1337/chat', $loop, $resolver);
//Most WS servers will complain/forbid if there is no origin header
$client->setOrigin('127.0.0.1');
$client->connect();
$client->on('stateChange', function($newState){
echo "State changed to: $newState\n";
});
$client->on('message', function($message) use ($client){
echo "New message: \n";
echo $message;
$client->send('This is a response message');
});
$loop->run();