Giter Club home page Giter Club logo

bolt's Introduction

bolt

Asynchronous WebSocket client client library for PHP. Supports HyBi, as well as Hixie #76 (no point).

This was built purely to be a client, as the majority of the WS clients available also contain servers and are very bloated.

Installation

Using composer:

composer require calcinai/bolt   

Usage

Since this really lends itself to being an asynchronous app, it is built to use the React event loops and resolver since there's a good chance they'll be in your project already and this lets you attach to the same loop.

$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();

Other available events are connecting, connect, disconnecting, disconnect

HTTP basic auth is also supported via the URI inf the form user:pass@host

Any feedback is most welcome

bolt's People

Contributors

calcinai avatar mattrenner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bolt's Issues

$client->setOrigin

Thanks God, at last working php websocket client. Except $client->setOrigin, that function is not implemented.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.