falk0069 / hue-upnp

Philips Hue UPNP and HTTP emulator (works with the Android Hue app and Logitech Harmony Home Remotes)
30 stars 10 forks source link

Reuse HTTP address #11

Closed dstmar closed 8 years ago

dstmar commented 8 years ago

I'm having issues when restarting hueUpnp because the HTTP port is still in a TIME_WAIT state. I've managed to get it working by setting allow_reuse_address on SocketServer.ThreadingTCPServer before an instance is created, instead of setting it on the instance of self.server itself.

Currently (around line 247): self.server = SocketServer.ThreadingTCPServer((CONFIG.standard['IP'], CONFIG.standard['HTTP_PORT']), HttpdRequestHandler) self.server.allow_reuse_address = True

The following seems to work for me: SocketServer.ThreadingTCPServer.allow_reuse_address = True self.server = SocketServer.ThreadingTCPServer((CONFIG.standard['IP'], CONFIG.standard['HTTP_PORT']), HttpdRequestHandler)

falk0069 commented 8 years ago

Dstmar,

Thanks for the code example. I'll experiment a bit with the reuse option but I'm a bit hesitant to use it on the httpd portion. The reason being that I'm not sure what would happen if you actually did have another server already running on the same port or had a second copy of this script running. The only time I run into this TIME_WAIT issue is when I'm frequently starting and stopping the script while troubleshooting. For the most part once someone gets things work, they will never have this issue again.

I'll let you know what I think after experimenting a bit.

Thanks

--Andy

falk0069 commented 8 years ago

Dstmar,

Your code suggestion works great! It still prevents duplicate servers from running and yet allows to start if only TIME_WAITs exist. Thanks for your contribution. I'll be adding it to source. Thanks

dstmar commented 8 years ago

Good to hear. Update works on my end.

Thanks for this great software, can't believe the Harmony still doesn't support WOL.