workman创建wss服务

时间:2018-01-08 09:24:46 阅读:771次
workman创建wss服务

nginx配置

server {

    listen 443;

    server_name 您的域名;

    ssl on;

    root html;

    index index.html index.htm;


    ssl_certificate  test.pem;

    ssl_certificate_key  test.key;

    ssl_session_timeout 5m;

    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_prefer_server_ciphers on;


    location / {

        proxy_pass https://您的域名:4431;

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection "Upgrade";

        proxy_set_header X-Real-IP $remote_addr;

    }

}


workman代码

//start_gateway.php
$context = array(
    'ssl' => array(
        // 使用绝对路径
        'local_cert'  => 'test.pem',
        'local_pk'    => 'test.key',
        'verify_peer' => false,
    )
);
$gateway = new Gateway("websocket://您的域名:4431",$context);
$gateway->name = 'WzqGateway';
$gateway->count = 1;
$gateway->transport = 'ssl';
$gateway->lanIp = '127.0.0.1';
$gateway->startPort = 4000;
$gateway->pingInterval = 60;
$gateway->pingData = '{"message_type":"ping"}';
$gateway->registerAddress = '127.0.0.1:2236';
//start_businessworker.php
$worker = new BusinessWorker();
// worker名称
$worker->name = 'WzqBusinessWorker';
$worker->count = 1;
$worker->transport = 'ssl';


前端代码测试


ws = new WebSocket("wss://域名");
ws.onopen = function() {
    alert("连接成功");
    ws.send('tom');
    alert("给服务端发送一个字符串:tom");
};
ws.onmessage = function(e) {
    alert("收到服务端的消息:" + e.data);
};

扫描二维码关注程序员爱笔记,接收更多资讯

评论

快速评论