How to stop a Webserver ?
John Sandgrounder (1650) 574 posts |
I have a “web server” application (based on Stuart Brodie’s !HTTPserver. This simple amplication deals with HTTP requests on a high numbered port. The traffic rate is very low for such a server, so the Pi has no trouble with the transfers. Even with many copies running on 40 or so ports. Everything is fine until I stop a Task (or it crashes). Because I then get an error message when I try to start it again – “bind() failed – Address aleady in use” The work around, of course, is never to let the Wimp Task stop (even during software updates), but every now and again I get the (BBC Basic) code wrong and the ON ERROR does not handle it properly (Resulting in having to reboot the system to fix the problem. :( I have long since lost my original copy of Stuart’s !HTTPserver. If any body has a copy, I would very much like to know how I should close down the server port binding. |
Raik (463) 2029 posts |
Maybe it helps you try a other one. |
John Sandgrounder (1650) 574 posts |
I already have a full web server. Webjames works very well, but as with the one in your link there is no source code from which to learn how it works. |
Rick Murray (539) 13422 posts |
WebJames has source. But the basic trouble is when your application dies it is not closing the socket (shutdown() if using TCPIPLib). You cannot later “bind” to a port already in use. |
Andrew Conroy (370) 725 posts |
Not code to learn from, but when I’m working with sockets I use !SocketMgr by Dave Thomas which allows you to see which sockets are currently open and individually close them. It relies on the IServices module, which isn’t 32bit, but does work happily under Aemulor. Very handy when your code crashes and leaves a socket open. |
Steve Pampling (1551) 7952 posts |
One thing I will say from this: It’s sort of good1 to know the socket problem can be reproduced regularly. I mentioned crashes with WebJames previously but as I said then it was always difficult to reproduce. 1 While a bug is a royal pain being able to reproduce the fault tends to make the problem easier to identify and fix. |
Philip J Ludlam (50) 21 posts |
Or you can Launch !Director – http://director.sf.net – and close network sockets from: |
Steve Pampling (1551) 7952 posts |
Good work around, but I rather felt that being able to trigger the problem would give a better opportunity for finding and fixing the base issue that the doesn’t recover automatically from the situation. I’ve always found nebulous, unreproducible problems are the hardest to fix (because you can’t study it when it isn’t there) |
John Sandgrounder (1650) 574 posts |
@Andrew Conroy, I have alread tried SocketMgr, but it doues not run on a Raspberry Pi. (presumably not 32 bit compliant). @all, Thanks for the comments. My code is slowly getting better in that I can now execute a controlled shutdown The fault tolerance is also improving; In most cases, the code can simply restart using the existing port binding. |
Andrew Conroy (370) 725 posts |
It relies on the IServices module, which isn’t 32bit, but does work happily under Aemulor. |
Steve Pampling (1551) 7952 posts |
Seems to work quite happily as a 32 bit version if you hack it a bit. |
Andrew Conroy (370) 725 posts |
Unfortunately my programming skills don’t extend much beyond PRINT “Hello world!”, I wouldn’t have the first clue what the output ARMalyser generated meant, still less what to do with it from there. With it being Justin’s work, I guess we can’t distribute/pass on hacked modules anyway. |
Steve Pampling (1551) 7952 posts |
Correct, irrespective of the author. |