91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

workerman實現群聊

發布時間:2020-08-09 06:03:24 來源:網絡 閱讀:564 作者:Lee_吉 欄目:web開發
  1. 服務端:
    <?php
    require_once "vendor/autoload.php";
    use dollarphp\autofunction;
    use dollarphp\errorhandle;
    new autofunction('function');
    new errorhandle();
    use Workerman\Worker;
    use GatewayWorker\Gateway as gate;
    use GatewayWorker\BusinessWorker;
    use GatewayWorker\Register;
    use GatewayWorker\Lib\Gateway;
    $gateway = new gate("websocket://0.0.0.0:2345");
    $gateway->startPort = 30000;
    $gateway->count = 4;
    $gateway->name = 'gateway';
    $gateway->registerAddress = '127.0.0.1:1234';
    $business = new BusinessWorker();
    $business->count = 4;
    $business->registerAddress = '127.0.0.1:1234';
    $register = new Register('text://0.0.0.0:1234');
    $register->name = 'register';
    class Events{
    public static function onConnect($client_id){
        return GateWay::sendToCurrentClient('welcome');
    }
    public static function onMessage($client_id, $message){
        $arr = array(
                'remote_ip'=>$_SERVER['REMOTE_ADDR'],
                'remote_port'=>$_SERVER['REMOTE_PORT'],
                'gate_ip'=>$_SERVER['GATEWAY_ADDR'],
                'gate_port'=>$_SERVER['GATEWAY_PORT'],
                'client_id'=>$_SERVER['GATEWAY_CLIENT_ID'],
            );
        var_dump($arr);
        return GateWay::sendToCurrentClient($message);
    }
    public static function onClose($client_id){
       GateWay::sendToAll("client[$client_id] logout\n");
    }
    }
    Worker::runAll();
  2. 客戶端:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    </head>
    <body>
    <input type="text">
    <br>
    <input type="button" value="提交">
    <script>
        var ws = new WebSocket('ws://192.168.8.81:2345')
        ws.onopen = function(data) {
            console.log('連接開始\n')
        }
        ws.onmessage = function(data) {
            console.log('接收消息:'+data.data)
        }
        ws.onclose = function(data) {
            console.log('關閉連接\n')
        }
        ws.onerror = function(data) {
            console.log('遇到錯誤\n')
        }
        var text = document.getElementsByTagName('input')[0]
        var button = document.getElementsByTagName('input')[1]
        button.onclick = function(){
            var val = text.value
            ws.send(val)
        }
    </script>
    </body>
    </html>
  3. 效果:
    workerman實現群聊
    workerman實現群聊
    workerman實現群聊
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

稷山县| 沅江市| 登封市| 达孜县| 庆云县| 兴化市| 丹寨县| 民县| 柞水县| 井冈山市| 耿马| 新昌县| 德钦县| 五常市| 宜黄县| 资源县| 绥德县| 清水县| 黄骅市| 崇文区| 东山县| 抚松县| 铁岭县| 陈巴尔虎旗| 平南县| 黄梅县| 鄢陵县| 双城市| 南投县| 博爱县| 五峰| 得荣县| 南漳县| 泽州县| 黄龙县| 三门峡市| 建德市| 德江县| 临夏县| 于都县| 岫岩|