gos/websocket-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gos/websocket-client

最新稳定版本:v1.5.0

Composer 安装命令:

composer require gos/websocket-client

包简介

WAMP client in PHP

README 文档

README

NOTE - This repository is deprecated, future releases will only be made for critical bugs and security vulnerabilities. Use Pawl instead.

WebSocketPhpClient

Latest Stable Version Latest Unstable Version Total Downloads License

About

This package provides a PHP client that can send messages to a websocket server utilizing the WAMPv1 protocol. Listening for replies is not supported at this time.

Supported functions:

  • prefix
  • call
  • publish
  • event

Usage

Directly Create A Client

You can directly create a Gos\Component\WebSocketClient\Wamp\ClientInterface instance by creating a new Gos\Component\WebSocketClient\Wamp\Client object. The constructor has two mandatory requirements; the server host and port. You may review the Client class constructor to see all arguments.

<?php
use Gos\Component\WebSocketClient\Wamp\Client;

$client = new Client('127.0.0.1', 8080);

Through The Factory

A Gos\Component\WebSocketClient\Wamp\ClientFactoryInterface is available to create client instances as well. The default Gos\Component\WebSocketClient\Wamp\ClientFactory supports a PSR-3 logger and will automatically inject it into the client if one is present.

<?php
use Gos\Component\WebSocketClient\Wamp\ClientFactory;

$factory = new ClientFactory(['host' => '127.0.0.1', 'port' => 8080]);
$client = $factory->createConnection();

Interact With Server

Once you have created a client, you can connect and interact with your websocket server.

<?php
use Gos\Component\WebSocketClient\Wamp\ClientFactory;

$factory = new ClientFactory(['host' => '127.0.0.1', 'port' => 8080]);
$client = $factory->createConnection();

$sessionId = $client->connect();

// Establish a prefix on server
$client->prefix('calc', 'http://example.com/simple/calc#');

// You can send an arbitrary number of arguments
$client->call('calc', 12, 14, 15);

$data = [0, 1, 2];

// Or an array
$client->call('calc', $data);

$exclude = [$sessionId]; // No sense in sending the payload to ourselves
$eligible = []; // List of other clients ids that are eligible to receive this payload

$client->publish('topic', '', $exclude, $eligible);

// Publish an event
$client->event('topic', '');
$client->disconnect();

License

This software is distributed under MIT License. See LICENSE for more info.

Original Project

https://github.com/bazo/wamp-client

统计信息

  • 总下载量: 2.22M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 35
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 33
  • Watchers: 4
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-09