File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed
Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments