定制 thruway/client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thruway/client

最新稳定版本:0.5.8

Composer 安装命令:

composer require thruway/client

包简介

Thruway WAMP client

README 文档

README

Build Status

Thruway

Thruway Client is an open source client for Thruway and the WAMP (Web Application Messaging Protocol), for PHP.

Thruway uses (reactphp); an event-driven, non-blocking I/O model, 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
  • Publish & Subscribe
    • Subscriber Black and Whitelisting
    • Publisher Exclusion
    • Publisher Identification
  • Remote Procedure Calls
    • Caller Identification
    • Progressive Call Results
    • Caller Exclusion
    • Canceling Calls

* Thruway specific features

Requirements

Thruway Client is only supported on PHP 5.6 and up.

Quick Start with Composer

The below instructions actually install the Thruway Router and Client for test purposes. The client can also be installed without the router in your own project.

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.

统计信息

  • 总下载量: 804.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 6
  • 推荐数: 1

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-06