-
-
This may be user error, as the espruino websocket server example works when the client is a web browser. when trying to get the client to be a node.js app, i'm having issues.
this gives the same error from node.js. i can see the blue light flash on the espruino when i run the client, but there is no output in the espruino repl.
is there an example for espruino websocket server, and node.js client?
const WebSocket = require('ws'); const ws = new WebSocket('ws://192.168.1.203:8000/'); ws.on('open', function open() { ws.send('something'); }); ws.on('error', function(err) { console.log(err); }) ws.on('message', function incoming(data) { console.log(data); });
-
i have confirmed that 1v96 works with espruino as the websocket client. i am still receiving an error when espruino is the server, using the example code, and i use this code in node.js
Error: Server sent a subprotocol but none was requested
const WebSocket = require('ws'); const ws = new WebSocket('ws://192.168.1.203:8000/', { protocol : "echo-protocol", protocolVersion: 13 }); ws.on('open', function open() { ws.send('something'); }); ws.on('error', function(err) { console.log(err); }) ws.on('message', function incoming(data) { console.log(data); });
-
thanks @Gordon. conversely, when trying to run a websocket server on the espruino, and connect from a node.js client, i get the error:
Error: Server sent a subprotocol but none was requested
and the client disconnects. i will try 1v96 today.
-
-
when attempting to follow the websocket client example at http://www.espruino.com/ws, i get errors on the server (running node.js on a windows10 laptop) as:
RangeError: Invalid WebSocket frame: RSV1 must be clear
When I modify the code to use the npm ws client on the laptop, it works fine.
server:
node 8.9.4,
"dependencies": {"express": "^4.16.3", "http": "0.0.0", "url": "^0.11.0", "ws": "^5.1.1"
}
espruino wifi client:
1v97function wsConnect() { ws = new WebSocket(host, {path: '/', perMessageDeflate: false, port: 8080}); ws.on('open', function() { // For WebSocket clients only console.log("Connected to server"); }); ws.on('message', function(msg) { console.log("MSG: " + msg); }); ws.on('close', function() { console.log("Connection closed"); }); ws.on('handshake', function() { console.log("Handshake Success"); }); ws.on('ping', function() { console.log("Got a ping"); }); ws.on('pong', function() { console.log("Got a pong"); }); ws.on('rawData', function(msg) { console.log("RAW: " + msg); }); }
output on the repl is
wsConnect()
=undefined
RAW: HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: j5MohIRvl3Pm9AVPI+aTUTQIKxI=
Handshake Success
Connected to server
RAW: something
MSG: something
RAW: something
MSG: something
Connection closed
Connection closed
there were other regressions with 1v97.60, e.g. the getPage() example did not return a page. reverting to 1v97 or 1v96 does work. i'll wait for an official release to move forward from 1v96 for now.