From 715eb48364369b739515864987c2e89b6a56a38f Mon Sep 17 00:00:00 2001 From: Jordan Rey Date: Tue, 8 Jul 2025 11:11:01 +0200 Subject: [PATCH 1/2] fix: keepalive on the server side & bump to 1.7.4 --- README.md | 4 ++-- pom.xml | 2 +- src/main/java/com/arenareturns/simplenet/Server.java | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7ec37b1..cf6fe17 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ Maven: com.arenareturns SimpleNet - 1.7.3 + 1.7.4 ``` Gradle: ```groovy -implementation 'com.arenareturns:SimpleNet:1.7.3' +implementation 'com.arenareturns:SimpleNet:1.7.4' ``` 2. Because SimpleNet is compiled with Java 11, you must first require its module in your `module-info.java`: diff --git a/pom.xml b/pom.xml index cb380bb..de32a97 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.arenareturns SimpleNet - 1.7.3 + 1.7.4 SimpleNet ArenaReturns' fork of SimpleNet, an easy-to-use, event-driven, asynchronous network application framework compiled with Java 11. diff --git a/src/main/java/com/arenareturns/simplenet/Server.java b/src/main/java/com/arenareturns/simplenet/Server.java index 5605b72..6c48f63 100644 --- a/src/main/java/com/arenareturns/simplenet/Server.java +++ b/src/main/java/com/arenareturns/simplenet/Server.java @@ -46,6 +46,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import jdk.net.ExtendedSocketOptions; /** * The entity that all {@link Client}s will connect to. @@ -138,6 +139,16 @@ public void bind(String address, int port, int numThreads) { channel.accept(null, new CompletionHandler() { @Override public void completed(AsynchronousSocketChannel channel, Void attachment) { + try { + // Configure TCP keepalive settings for the client connection + channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); + channel.setOption(ExtendedSocketOptions.TCP_KEEPCOUNT, 3); + channel.setOption(ExtendedSocketOptions.TCP_KEEPIDLE, 30); + channel.setOption(ExtendedSocketOptions.TCP_KEEPINTERVAL, 5); + } catch (IOException e) { + LOGGER.debug("Failed to set keepalive options on client socket", e); + } + Client client = new Client(channel); connectedClients.add(client); client.postDisconnect(() -> connectedClients.remove(client)); From cb385ad6a5a8c64b0c823fbb9829bcf66d29c452 Mon Sep 17 00:00:00 2001 From: Jordan Rey Date: Tue, 8 Jul 2025 11:12:33 +0200 Subject: [PATCH 2/2] should be a warning --- src/main/java/com/arenareturns/simplenet/Server.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/arenareturns/simplenet/Server.java b/src/main/java/com/arenareturns/simplenet/Server.java index 6c48f63..2f19fca 100644 --- a/src/main/java/com/arenareturns/simplenet/Server.java +++ b/src/main/java/com/arenareturns/simplenet/Server.java @@ -146,7 +146,7 @@ public void completed(AsynchronousSocketChannel channel, Void attachment) { channel.setOption(ExtendedSocketOptions.TCP_KEEPIDLE, 30); channel.setOption(ExtendedSocketOptions.TCP_KEEPINTERVAL, 5); } catch (IOException e) { - LOGGER.debug("Failed to set keepalive options on client socket", e); + LOGGER.warn("Failed to set keepalive options on client socket", e); } Client client = new Client(channel);