关于GatewayClient 介绍和使用

匿名 (未验证) 提交于 2019-12-03 00:39:02

GatewayClient

## 源码

https://github.com/walkor/GatewayClient

根据GatewayWorker版本,选择合适的GatewayClient版本,请参照【如何知道使用的GatewayWorker版本号?

注意:GatewayClient3.0.0以后支持composer并加了命名空间GatewayClient

注意:

1.如果GatewayClientGatewayWorker不是在同一台服务器上,则需要先将start_gateway.php中的lanIp改成当前服务器的内网ip(如果不在一个内网可改成公网ip)。

2.如果GatewayClient和GatewayWorker在同一台服务器上运行,则不用做任何更改,直接按照示例使用GatewayClient即可。

3.通过GatewayClient发送的数据不会经过Event.php,而是直接经由Gateway进程转发给客户端

4.GatewayClient无法接收客户端发来的数据。

## 安装(composer安装适用于3.0.0及以上版本)

composer require workerman/gatewayclient

require_once ‘/your/path/GatewayClient/Gateway.php‘;  /**  * gatewayClient 3.0.0及以上版本加了命名空间  * 而3.0.0以下版本不需要use GatewayClient\Gateway;  **/ use GatewayClient\Gateway;  /**  *====这个步骤是必须的====  *这里填写Register服务的ip(通常是运行GatewayWorker的服务器ip)和端口  *注意Register服务端口在start_register.php中可以找到(chat默认是1236)  *这里假设GatewayClient和Register服务都在一台服务器上,ip填写127.0.0.1  *注意:ip不能是0.0.0.0  **/ Gateway::$registerAddress = ‘127.0.0.1:1236‘;   // 以下是调用示例,接口与GatewayWorker环境的接口一致 // 接口具体使用方法见《Lib\Gateway类提供的接口》一章 // 注意除了不支持sendToCurrentClient和closeCurrentClient方法 // 其它方法都支持 Gateway::sendToAll($data); Gateway::sendToClient($client_id, $data); Gateway::closeClient($client_id); Gateway::isOnline($client_id); Gateway::bindUid($client_id, $uid); Gateway::isUidOnline($uid); Gateway::getClientIdByUid($uid); Gateway::unbindUid($client_id, $uid); Gateway::sendToUid($uid, $data); Gateway::joinGroup($client_id, $group); Gateway::sendToGroup($group, $data); Gateway::leaveGroup($client_id, $group); Gateway::getClientCountByGroup($group); Gateway::getClientSessionsByGroup($group); Gateway::getAllClientCount(); Gateway::getAllClientSessions(); Gateway::setSession($client_id, $session); Gateway::updateSession($client_id, $session); Gateway::getSession($client_id);

原文:https://www.cnblogs.com/feixiablog/p/9264412.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!