这次,我尝试了可以??通过命令行处理WebSocket的wscat,因此请记下
启动Docker容器
1 | docker run --rm -it -p 8080:8080 --name wscat-test takashioshikawa/php5.6.17 |
创建工作目录
1 | mkdir /src && cd /src |
下载WebSocket测试
1 | wget https://github.com/TakashiOshikawa/ratchet-test/archive/master.zip |
解压缩
1 | unzip master.zip |
1 | cd ratchet-test-master/ |
安装node.js和npm
单击此处以获取参考centos node.js npm nvm安装
1 2 3 | yum install -y epel-release yum install -y nodejs yum install -y npm --enablerepo=epel |
wscat安装
1 | npm install -g wscat |
启动WebSocket应用并与wscat
连接
在后台运行WebSocket应用
1 | php bin/chat-server.php & |
与wscat连接
1 | wscat -c localhost:8080/chat |
如果看到这样的字符,就可以了
1 2 3 4 5 6 7 8 | [root@ec5ce01ae845 ratchet-test-master]# wscat -c localhost:8080/chat New connection! (58) connected (press CTRL+C to quit) > dd Connection 58 sending message "dd" to 0 other connections > aa Connection 58 sending message "aa" to 0 other connections > |