Last active
August 29, 2015 14:23
-
-
Save tsaylor/e20e044642785aea9868 to your computer and use it in GitHub Desktop.
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
Requires Websocketd (http://websocketd.com/) | |
Run this command: | |
./websocketd --port=8080 ./server.sh | |
Include socketlog.js on your page and call | |
log('log message') | |
to log a message. See the log messages in /tmp/ws.log. |
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
#!/bin/bash | |
read a; echo $a >> /tmp/ws.log |
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
var wsUri = "ws://localhost:8080/"; | |
function log(msg) { | |
websocket = new WebSocket(wsUri); | |
websocket.onopen = function(evt) {doSend(msg)}; | |
websocket.onclose = function(evt) {onClose(evt)}; | |
websocket.onmessage = function(evt) {onMessage(evt)}; | |
websocket.onerror = function(evt) {onError(evt)}; | |
} | |
function onMessage(evt) { console.log(evt.data); } | |
function onClose(evt) { console.log(evt.data); } | |
function onError(evt) { console.log(evt.data); } | |
function doSend(message) { websocket.send(message); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment