linux 安装 websocketd
1.下载
wget https://github.com/joewalnes/websocketd/releases/download/v0.3.0/websocketd-0.3.0-linux_amd64.zip
注意如果下载不了请通过手动下载到本地再通过FTP上传到服务器
2.解压
unzip websocketd-0.3.0-linux_amd64.zip
3.复制websocketd到/usr/bin
cp ./websocketd /usr/bin/websocketd
4.添加到path
echo "export PATH=$PATH:/usr/bin/websocketd" >> /etc/profile
source /etc/profile
5.启动服务
websocketd --help # 查看帮助
[root@localhost-db01 ~]# websocketd --address=0.0.0.0 --port=8888 ls
浏览器 console 测试连接,可以看到 ls 命令的输出:
<script>
var ws = new WebSocket('ws://ip:port');
ws.onopen = function(event){console.log("CONNECT")};
ws.onmessage = function(event){console.log(event.data)};
ws.onerror = function(event){console.log(event)};
</script>