php编译出错onMessage,php7.1.5/swoole2.08 websocket onmessage 没数据输出

js

var wsServer = 'ws://127.0.0.1:9502';

//调用websocket对象建立连接:

//参数:ws/wss(加密)://ip:port (字符串)

var websocket = new WebSocket(wsServer);

//onopen监听连接打开

websocket.onopen = function (evt) {

console.log('this is a test')

//websocket.readyState 属性:

/*

CONNECTING 0 The connection is not yet open.

OPEN 1 The connection is open and ready to communicate.

CLOSING 2 The connection is in the process of closing.

CLOSED 3 The connection is closed or couldn't be opened.

*/

};

//监听连接关闭

websocket.onclose = function (evt) {

console.log("Disconnected");

};

//onmessage 监听服务器数据推送

websocket.onmessage = function (evt) {

console.log(evt);

// console.log('Retrieved data from server: ' + evt.data);

};

//监听连接错误信息

websocket.onerror = function (evt, e) {

console.log('Error occured: ' + evt.data);

};

php

$serv = new Swoole\Websocket\Server("127.0.0.1", 9502);

$serv->on('Open', function($server, $req) {

echo "connection open: ".$req->fd;

});

$serv->on('Message', function($server, $frame) {

echo "message: ".$frame->data;

$server->push($frame->fd, json_encode(["hello", "world"]));

});

$serv->on('Close', function($server, $fd) {

echo "connection close: ".$fd;

});

$serv->start();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值