Skip to content

Commit 7b40947

Browse files
author
jianyan74
committed
修改说明,增加案例
1 parent 00c79b0 commit 7b40947

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
即时通讯,直播间demo
44

5-
### 前提安装swoole
5+
### 前提
6+
7+
安装swoole
68

79
```
810
git clone https://github.com/swoole/swoole-src.git
@@ -53,4 +55,30 @@ composer require "jianyan74/yii2-websocket"
5355
php ./yii web-socket/stop
5456
# 重启
5557
php ./yii web-socket/restart
56-
```
58+
```
59+
60+
### 测试
61+
62+
```
63+
<script>
64+
var wsl = 'wss://[to your url]:9501';
65+
ws = new WebSocket(wsl);// 新建立一个连接
66+
// 如下指定事件处理
67+
ws.onopen = function () {
68+
// ws.send('Test!');
69+
};
70+
// 接收消息
71+
ws.onmessage = function (evt) {
72+
console.log(evt.data);
73+
/*ws.close();*/
74+
};
75+
// 关闭
76+
ws.onclose = function (evt) {
77+
console.log('WebSocketClosed!');
78+
};
79+
// 报错
80+
ws.onerror = function (evt) {
81+
console.log('WebSocketError!');
82+
};
83+
</script>
84+
```

0 commit comments

Comments
 (0)