jczic / MicroWebSrv

A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWebSrv
MIT License
645 stars 116 forks source link

nmap scan stops MicroWebSrv #44

Closed dl2080 closed 5 years ago

dl2080 commented 6 years ago

Hello, thank you for this nice web server project!

I'm using nmap to discover devices in my network. However, as soon as I start the scan in the linux console, MicroWebSrv on my WiPy 3.0 stops working. After that, restarting the server with srv.Start() fails due to [Errno 12] ENOMEM. I found that I need to close the socket first. srv.Stop() will not help, because it closes only, if srv._started is true, which is not the case. Maybe this can be changed? srv._server.close() helps. After that a restart of the server is possible without reseting the whole device.

To trace the cause of the server stop error, I changed the try/except block in microWebSrv.py line 239 to

try :
   client, cliAddr = self._server.accept()
except Exception as e :
   print(str(e))
   break

I get [Errno 128] ENOTCONN when nmap starts.

It seems some connection is being lost. Is there a way to prevent MicroWebSrv from stopping at this position?

nmap has version 7.60 wipy firmware is 1.19.0.b4 micropython has version 1.9.4 Server is started with:

srv = MicroWebSrv(routeHandlers = routeHandlers)
srv.MaxWebSocketRecvLen = 256
srv.WebSocketThreaded = True
srv.AcceptWebSocketCallback = _acceptWebSocketCallback
srv.Start(threaded = True)
jczic commented 5 years ago

Hello, Yes I see that ! I've just updated the code to close server only if the error code is 113 (normal closing socket). You can check at : https://github.com/jczic/MicroWebSrv/commit/5074d96203d32c049b66577013cad90ea8e21327 That's ok for you ? Thanks !

dl2080 commented 5 years ago

Yes, it doesn't crash anymore! Great! Thanks a lot!

jczic commented 4 years ago

Hello,

I released a fully new version (v2.0) of my web server here : github.com/jczic/MicroWebSrv2. Open source MIT, fully asynchronous, more robust, more fast and more efficient! It is delivered with a good documentation.

Thank you for your support and feedback. ☺️

Jean-Christophe Bos

Le jeu. 11 oct. 2018 à 21:43, dl2080 notifications@github.com a écrit :

Closed #44 https://github.com/jczic/MicroWebSrv/issues/44.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jczic/MicroWebSrv/issues/44#event-1899153367, or mute the thread https://github.com/notifications/unsubscribe-auth/AAegLITfxSGlIjtWifgs0DPeaPTN_2B1ks5uj59qgaJpZM4W6-K2 .

--

Sincèrement,