espruino / EspruinoTools

JavaScript library of tools for Espruino - used for the Web IDE, CLI, etc.
Apache License 2.0
150 stars 89 forks source link

close websockets at reset #83

Closed Matthias-Hermsdorf closed 6 years ago

Matthias-Hermsdorf commented 6 years ago

Hi, the websocketserver does not die propper on reset() or reset(true).

Say I have this Server.

function onPageRequest(req, res) {
   res.writeHead(200, {'Content-Type': 'text/html'});
    res.end("Hi. Ask the other Server");
}

var server = require('ws').createServer(onPageRequest);
server.listen(80);
console.log("server listen on port",80);

server.on("websocket", function(ws) {
ws.on('message',function(msg) {
    console.log("msg",msg);
    });
});

I deploy the code with espruino -m -p tcp://192.168.178.56 socketTest.js to the Board, everything is fine. I could connect to this SocketServer and can send Messages.

But if I want to deploy the next commit, I get a

>ERROR: Socket bind failed
--] Uncaught InternalError: Unable to create socket

This only happens if I establish a connection in between. If the socketServer is unloaded, it should close ists connections.

I could store the sockets. But this variable isn't accessible at the next upload.

I use Espruino Command-line Tool 0.1.13 and Espruino 1.99

gfwilliams commented 6 years ago

Which board are you using, and which firmware version? This is the GitHub repository for the Espruino CLI, and it looks like your problem is related to Espruino itself.

My guess is you are using either ESP8266 or ESP32, in which case please can you ask in their specific area of the forum? http://forum.espruino.com/microcosms/1085/

ESP32 especially has had some changes recently to fix exactly this kind of issue.

Matthias-Hermsdorf commented 6 years ago

Nice guess. Yes, it is a ESP32 and a 1.99 And thanks to the immediate reply

gfwilliams commented 6 years ago

Yeah, I'd ask on the forums as the folks on there know a lot more about it, but if you use a cutting edge build from http://www.espruino.com/binaries/travis/master/ you may find it just works :)

Matthias-Hermsdorf commented 6 years ago

My last build was five days old. And with the current build it works. fine.

gfwilliams commented 6 years ago

It was fixed yesterday! https://github.com/espruino/Espruino/commit/5b07121317d0028a7253e3fa47c12b3383e09ceb