GithubHelp home page GithubHelp logo

guoyu07 / thruway Goto Github PK

View Code? Open in Web Editor NEW

This project forked from voryx/thruway

0.0 0.0 0.0 1.08 MB

PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging

License: MIT License

PHP 99.73% Shell 0.07% HTML 0.20%

thruway's Introduction

Build Status

Thruway

Thruway is an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP. Thruway uses an event-driven, non-blocking I/O model (reactphp), perfect for modern real-time applications.

Supported WAMP Features

Basic Spec read more

  • Publish and Subscribe
  • Remote Procedure Calls
  • Websocket Transport
  • Internal Transport*
  • JSON serialization

Advanced Spec read more

  • RawSocket Transport
  • Authentication
  • WAMP Challenge-Response Authentication
  • Custom Authentication Methods
  • Authorization
  • Publish & Subscribe
  • Subscriber Black and Whitelisting
  • Publisher Exclusion
  • Publisher Identification
  • Subscriber Meta Events
  • Event History*
  • Subscription Matching
  • Prefix matching
  • Remote Procedure Calls
  • Caller Identification
  • Progressive Call Results
  • Distributed Registrations & Calls*
  • Caller Exclusion
  • Canceling Calls

* Thruway specific features

Requirements

Thruway is only supported on PHP 5.4 and up.

Quick Start with Composer

Create a directory for the test project

  $ mkdir thruway

Switch to the new directory

  $ cd thruway

Download Composer more info

  $ curl -sS https://getcomposer.org/installer | php

Download Thruway and dependencies

  $ php composer.phar require voryx/thruway

Start the WAMP router

  $ php vendor/voryx/thruway/Examples/SimpleWsRouter.php

Thruway is now running on 127.0.0.1 port 9090

PHP Client Example

<?php

require __DIR__ . '/vendor/autoload.php';

use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;

$client = new Client("realm1");
$client->addTransportProvider(new PawlTransportProvider("ws://127.0.0.1:9090/"));

$client->on('open', function (ClientSession $session) {

    // 1) subscribe to a topic
    $onevent = function ($args) {
        echo "Event {$args[0]}\n";
    };
    $session->subscribe('com.myapp.hello', $onevent);

    // 2) publish an event
    $session->publish('com.myapp.hello', ['Hello, world from PHP!!!'], [], ["acknowledge" => true])->then(
        function () {
            echo "Publish Acknowledged!\n";
        },
        function ($error) {
            // publish failed
            echo "Publish Error {$error}\n";
        }
    );

    // 3) register a procedure for remoting
    $add2 = function ($args) {
        return $args[0] + $args[1];
    };
    $session->register('com.myapp.add2', $add2);

    // 4) call a remote procedure
    $session->call('com.myapp.add2', [2, 3])->then(
        function ($res) {
            echo "Result: {$res}\n";
        },
        function ($error) {
            echo "Call Error: {$error}\n";
        }
    );
});


$client->start();

Javascript Clients

You can also use AutobahnJS or any other WAMPv2 compatible client.

Here are some [examples] (https://github.com/tavendo/AutobahnJS#show-me-some-code)

Here's a plunker that will allow you to run some tests against a local router

For AngularJS on the frontend, use the Angular WAMP wrapper.

thruway's People

Contributors

davidwdan avatar mbonneau avatar binaek avatar pantsel avatar adamlc avatar wyrihaximus avatar cboden avatar ddelbondio avatar eichie avatar pronskiy avatar ftrrtf avatar oanhnn avatar

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.