linux安装websocketd服务
1.下载
wget https://github.com/joewalnes/websocketd/releases/download/v0.3.0/websocketd-0.3.0-linux_amd64.zip
注意是amd架构
2.解压
unzip websocketd-0.3.0-linux_amd64.zip
3.复制websocketd到/usr/bin
cp ./websocketd /usr/bin/websocketd
4.添加到path
vi /etc/profile
export PATH=$PATH:/usr/bin/websocketd
sudo source /etc/profile
5.启动服务
websocketd --port=8000 ./count.sh
前端链接测试代码:
var ws =new WebSocket('ws://IP:8000');
ws.onopen = function(event){console.log("CONNECT")};
ws.onmessage = function(event){console.log(event.data)};
ws.onerror = function(event){console.log(event)};
count.sh文件内容如下:
#!/bin/bash for ((COUNT = 1; COUNT <= 10; COUNT++)); do echo $COUNT sleep 1 done
示例效果如下: