Ok, just changed so the following works:
var page = '<html><body><script>var ws;setTimeout(function(){'; page += 'ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");'; page += 'ws.onmessage = function (event) { console.log("MSG:"+event.data); };'; page += 'setTimeout(function() { ws.send("Hello to Espruino!"); }, 1000);'; page += '},1000);</script></body></html>'; function onPageRequest(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(page); } var server = require('ws').createServer(onPageRequest); server.listen(8000); server.on("websocket", function(ws) { ws.on('message',function(msg) { print("[WS] "+JSON.stringify(msg)); }); ws.send("Hello from Espruino!"); });
All updated and documented here: http://www.espruino.com/ws
@Gordon started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ok, just changed so the following works:
All updated and documented here: http://www.espruino.com/ws