下拉刷新
Repository Details
Shared bynavbar_avatar
repo_avatar
HelloGitHub Rating
0 ratings
把命令行的输出 stdout 和 stderr 重定向为一个 websocket 服务的工具
FreeBSD-2-Clause
Claim
Collect
Share
17.4k
Stars
No
Chinese
Go
Language
No
Active
42
Contributors
56
Issues
No
Organization
0.4.1
Latest
1k
Forks
BSD-2-Clause
License
More
把命令行的输出 stdout 和 stderr 重定向为一个 websocket 服务的工具。运行步骤如下: 1. 安装命令:`brew install websocketd` 2. 创建 count.sh 内容如下 3. 运行 count.sh,命令:`./count.sh` 4. 启动一个 websocket server,命令:`websocketd --port=8080 ./count.sh` 5. 创建 html 文件,代码如下 6. 点击打开 count.html 文件,查看效果 ``` count.sh 文件内容如下 #!/bin/bash for ((COUNT = 1; COUNT <= 3; COUNT++)); do echo $COUNT sleep 1 done count.html 文件内容如下 <!DOCTYPE html> <pre id="log"></pre> <script> // helper function: log message to screen function log(msg) { document.getElementById('log').textContent += msg + '\n'; } // setup websocket with callbacks var ws = new WebSocket('ws://localhost:8080/'); ws.onopen = function() { log('CONNECT'); }; ws.onclose = function() { log('DISCONNECT'); }; ws.onmessage = function(event) { log('MESSAGE: ' + event.data); }; </script> ```
Included in:
Vol.32

Comments

Rating:
No comments yet