-
Notifications
You must be signed in to change notification settings - Fork 37
Add support for inherited sockets #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for inherited sockets #115
Conversation
@Cu3PO42 Really nice. I will try this out to see how it works. And yes, we might need to wait with releasing it until the unreleased version of Java WebSocket becomes a real release, as it might have some unwanted side-effects. Let's see. 🙂 |
Thanks for taking a look! The easiest way to test this is to run The expected behavior when using the above command is that the server should launch on port 7654 as soon as you start a bot, for example. Other than that, it should work exactly the same as if you had launched it the conventional way. |
c4b6102
to
907f949
Compare
@Cu3PO42 I have had a first look at the changes you made, and it is looking good to me. Since I am working mostly on a Windows 11 machine, I will setup Ubuntu on my system (again) so I can try out how it works. 🙂 I am pretty sure it will work just fine. While running the code locally, I found another issue with the server that I will try to fix. I hope it will not impact this PR. |
Thank you! This feature should work just fine inside WSL2, so you might get away with simply installing that. If I recall correctly, running |
Just a question about this implementation. Would be possible that socket activation could allow a bot to be reloaded without loosing the connection? |
Not really, no. You could use the same mechanism to pass a socket from one generation of your bot to the new version after you make some changes, but an open socket isn't all that useful. You would need an open WebSocket connection, which has a bunch of associated state. It is possible to also preserve that when A much more realistic approach for your scenario would be to write a thin proxy for the connection between bot and server. That should be possible with relatively little effort and honestly sounds like a good idea. This would be entirely unrelated to the changes introduced here, though. |
Thank you for your reply. I may consider creating a proxy later if it
proves to be more efficient than my current approach, which involves
several intermediate steps to observe changes in my bots during the game.
If others show interest, they might encourage me to do it or even take on
the task themselves.
Thanks, and sorry for the digression from the main topic
Il giorno dom 1 dic 2024 alle ore 16:56 Tobias Zimmermann <
***@***.***> ha scritto:
… Would be possible that socket activation could allow a bot to be reloaded
without loosing the connection?
Not really, no. You *could* use the same mechanism to pass a socket from
one generation of your bot to the new version after you make some changes,
but an open socket isn't all that useful. You would need an open WebSocket
connection, which has a bunch of associated state. It is possible to also
preserve that when execve-ing a new binary, but it would be very
complicated.
A much more realistic approach for your scenario would be to write a thin
proxy for the connection between bot and server. That should be possible
with relatively little effort and honestly sounds like a good idea. This
would be entirely unrelated to the changes introduced here, though.
—
Reply to this email directly, view it on GitHub
<#115 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7Z3HCNRSTHYLDBU2ZR7D2DMWSLAVCNFSM6AAAAABR6KM35GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBZHA3DGMZSGQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
907f949
to
d7565ce
Compare
d7565ce
to
25ad795
Compare
I released 1.6.0 yesterday :) |
…nary dependency to real version 1.6.0 just released.
… and exit, if the inherited channel is not supported to avoid a stack trace most users don't understand.
Thank you both! I'm excited to see this merged :-) |
...er/src/main/kotlin/dev/robocode/tankroyale/server/connection/MultiServerWebSocketObserver.kt
Outdated
Show resolved
Hide resolved
…ystem.inheritedChannel()
So now I want to test this feature? 🙂 EDIT 1: I found out how to set up the server with EDIT 2: Here's an a guide for how to setup the socket activation (work in progress). Guide to Systemd Socket Activation for Robocode ServerSocket Unit File SetupCreate a socket unit file at [Unit]
Description=Robocode Tank Royale Socket
[Socket]
ListenStream=7654
[Install]
WantedBy=sockets.target Important This configuration uses port 7654, which is the default for Robocode. Service Unit File SetupCreate a service unit file at [Unit]
Description=Robocode Tank Royale Server
Requires=robocode.socket
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/java -jar /opt/robocode/robocode-tankroyale-server-0.28.0.jar --port=inherit
WorkingDirectory=/opt/robocode/
TimeoutStartSec=30
StandardInput=socket
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target Important Assumes Robocode server jar is located in The You might need to add add a Socket Management CommandsEnable the socket: sudo systemctl enable robocode.socket Disable the socket: sudo systemctl disable robocode.socket Start the socket: sudo systemctl start robocode.socket Stop the socket: sudo systemctl stop robocode.socket Verification and MonitoringCheck service port availability: ss -tuln | grep 7654 Expected output when service is running:
View service logs (with real-time monitoring): journalctl -u robocode.service -n 50 -f Restarting the Servicesudo systemctl daemon-reload
sudo systemctl restart robocode.service Reading Service Statussudo systemctl status robocode.service Expected output:
|
Hi! I am so sorry, I have been swallowed up by life and work for the last couple of days. I did some research into socket inheritance on Windows and it is possible, but much more complicated than on Unix systems. It also requires a different, much more involved form of cooperation and does not seem to work with Java at all (without ugly JNI hacks at least). You are on the right track with your current configuration. There is a somewhat easier way to test this by simply running As for the issue you are currently experiencing, it is because Java follows an older convention for passing sockets than systemd defaults to. You need the following in your service file:
|
No need to be sorry. Everybody are busy these days before Christmas, myself included. 🙂 I found out yesterday, that the I have updated the guide and I will include this in the documentation when we do the 0.28.0 release soon with this feature included. 😊 I still need some minor adjustment before that. But I want to release soon! |
@Cu3PO42 @marci4 |
This PR implements support for using inherited sockets instead of opening a new socket on a specified port. The primary motivation for this feature is socket activation. It lets the Robocode server be started on demand as soon as a bot, controller or observer conects to it.
I also intend to use this feature to make orchestration of the server easier without dealing with port conflicts for my battle runner.
Finally, this also enables (indirect) IPv6 support by opening a v6 socket and passing it.
Currently, this relies on an unreleased version of Java WebSocket, so I have marked this as a draft. I'll update the PR once v1.6 of the library is released.