-
• #2
.close
should work - however you might be having troubles if you haven't calledserver.listen(port)
first I guess?What device are you using?
From your post history it seems like you may be using ESP32, in which case I guess there's a small chance that
.close
is buggy? I'm pretty sure it's been tested to death on official Espruino boards so I'd be very surprised if there was any trouble on those. -
• #3
Thanks for the reply Gordon. Yes it's for an ESP32 (ESP-WROOM-32) with Espruino build 1v94. Here's the full example where I get an error.
var http = require('http'); var server=http.createServer(function(req, res){ res.writeHead(200); res.end("Hello World"); console.log("res sent"); }).listen(80); setTimeout(function(){ server.close(); },5000);
And the error message I get
Uncaught Error: Field or method "close" does not already exist, and can't create it on undefined at line 1 col 7 server.close(); ^
The webserver continues to work before and after the error. I tried this on an ESP8226 and get the same error also.
Again, any help is very much appreciated.
-
• #4
Hi @cmo!
I am affraid that listen() returns nothing (unlike the node.js' one). I have submitted a new bug for this.
In the meantime the code would need to look as follows:
var http = require('http'); var server=http.createServer(function(req, res){ res.writeHead(200); res.end("Hello World"); console.log("res sent"); }); server.listen(80); setTimeout(function(){ server.close(); },5000);
-
• #5
It's fixed now.
But PLEASE - there's a massive heading right at the top of the forum. This bit of the forum is for official boards ONLY. There's an ESP32 forum here: http://forum.espruino.com/microcosms/1086/
It may seem petty but I support myself purely off of Espruino board sales - and as a way to convince people to buy my boards I offer support to them on these sections of the forum.
-
• #7
Thank you. I agree, I put this in the wrong forum.
Hello,
Is there an event to turn off an http server?
This doesn't seem to work even though it looks documented (httpSrv class):
Any help is appreciated. Thanks.