TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.53k stars 2.58k forks source link

Support for inherited sockets #1440

Open Cu3PO42 opened 3 days ago

Cu3PO42 commented 3 days ago

Is your feature request related to a problem? Please describe. I would like to implement socket activation for an application using Java WebSocket, specifically Robocode Tank Royale. Socket activation lets systemd start an application on demand when others try to connect to it.

Describe the solution you'd like Using System.inheritedChannel you can get access to a socket that was passed to the application as file descriptor 1. I'd like for there to be a constructor for WebSocketServer that, instead of taking a port and listen address, accepts a pre-existing Channel.

Describe alternatives you've considered My specific use-case would also be solved by a constructor that calls System.inheritedChannel itself, though I believe the other one I proposed is more flexible. Socket

Socket activation is not easily replaced and there is no clean strategy to emulate it without support from the application.

Thank you for consideration!

PhilipRoman commented 3 days ago

I like this idea. From briefly looking at the code, I don't see any obstacles - if the inherited file descriptor represents a listening socket, then a ServerSocketChannel should be returned by System.inheritedChannel, which is exactly what we need.