Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Maven:
<dependency>
<groupId>com.arenareturns</groupId>
<artifactId>SimpleNet</artifactId>
<version>1.7.3</version>
<version>1.7.4</version>
</dependency>
```

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`:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.arenareturns</groupId>
<artifactId>SimpleNet</artifactId>
<version>1.7.3</version>
<version>1.7.4</version>

<name>SimpleNet</name>
<description>ArenaReturns' fork of SimpleNet, an easy-to-use, event-driven, asynchronous network application framework compiled with Java 11.</description>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/arenareturns/simplenet/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -138,6 +139,16 @@ public void bind(String address, int port, int numThreads) {
channel.accept(null, new CompletionHandler<AsynchronousSocketChannel, Void>() {
@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.warn("Failed to set keepalive options on client socket", e);
}

Client client = new Client(channel);
connectedClients.add(client);
client.postDisconnect(() -> connectedClients.remove(client));
Expand Down