2017 © Pedro Peláez
 

library swoole-websocket-client

web 调用 swoole 的 websocket 服务器客户端

image

aiwhj/swoole-websocket-client

web 调用 swoole 的 websocket 服务器客户端

  • Wednesday, December 27, 2017
  • by aiwhj
  • Repository
  • 1 Watchers
  • 2 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 91 % Grown

The README.md

swoole_websocket_client

web 调用 swoole 的 websocket 服务器客户端(composer 版), (*1)

**fork https://github.com/gy36/swoole_websocket_client **, (*2)

1. 安装

需要安装 swoole 拓展, (*3)

composer require aiwhj/swoole-websocket-client

2.服务端

基于 swoole_websocket_server 接口实现 websocket 服务, (*4)

<?php

$server = new swoole_websocket_server("0.0.0.0", 2345);

$server->on('open', function (swoole_websocket_server $server, $request) {
    echo "server: handshake success with fd{$request->fd}\n";
});

$server->on('message', function (swoole_websocket_server $server, $frame) {
    echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
    $server->push($frame->fd, "this is server");
});

$server->on('close', function ($ser, $fd) {
    echo "client {$fd} closed\n";
});

$server->start();

3. 客户端

<?php
namespace aiwhj\swooleWsClient;

require 'autoload.php';

$client = new WebSocket('127.0.0.1', 2345, '/VH4OKgcjVHZTPlFzBnVTYwExCS9RdFdwDX5VdwFiV3ADaFRjBio=');

echo '准备' . "<br>";

if (!($temp = $client->connect())) {
    var_dump($temp);
    echo "失败" . "<br>";
    echo "connect to server failed.\n";
    exit;
}
$message = json_encode(array('data' => '这是广播消息', 'to' => [1, 2, 3, 4, 5, 6, 7, 8, 9]), JSON_UNESCAPED_UNICODE);

$client->send($message);
$message = $client->recv();
echo '发送' . "<br>";
if ($message === false) {
    exit;
}
echo "Received from server: {$message}\n";

echo "Closed by server.\n";

The Versions

27/12 2017

dev-master

9999999-dev

web 调用 swoole 的 websocket 服务器客户端

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar gy36

client websocket swoole

26/12 2017

1.0.0

1.0.0.0

web 调用 swoole 的 websocket 服务器客户端

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Avatar gy36

client websocket swoole