Skip to content

Instantly share code, notes, and snippets.

@tsaylor
Last active August 29, 2015 14:23
Show Gist options
  • Save tsaylor/e20e044642785aea9868 to your computer and use it in GitHub Desktop.
Save tsaylor/e20e044642785aea9868 to your computer and use it in GitHub Desktop.
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.
#!/bin/bash
read a; echo $a >> /tmp/ws.log
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