Last active
March 30, 2017 03:34
-
-
Save wwj718/028e1aba3ce2c003f2900f8ab979503c to your computer and use it in GitHub Desktop.
信息管道,把任何本地程序映射为websocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head></head> | |
<body> | |
<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/'); | |
var ws = new WebSocket('ws://127.0.0.1:8080/'); | |
ws.onopen = function() { | |
log('CONNECT'); | |
}; | |
ws.onclose = function() { | |
log('DISCONNECT'); | |
}; | |
ws.onmessage = function(event) { | |
log('MESSAGE: ' + event.data); | |
}; | |
</script> | |
</body> | |
<!-- | |
https://github.com/joewalnes/websocketd | |
ngrok | |
websocketd --port=8080 ./count.sh | |
#!/bin/bash | |
for ((COUNT = 1; COUNT <= 10; COUNT++)); do | |
echo $COUNT | |
sleep 1 | |
websocket_test.py | |
https://github.com/joewalnes/websocketd/blob/master/examples/python/count.py | |
#!/usr/bin/env python | |
# encoding: utf-8 | |
import time | |
from sys import stdout | |
i=1 | |
while True: | |
time.sleep(1) | |
i=i+1 | |
print(i) | |
stdout.flush() | |
测试 | |
websocketd --port=8080 --dir=/tmp --devconsole | |
http://127.0.0.1:8080/greeter.py 选择 greeter.py 打勾 | |
--> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment