Minimal implementation of the RCON protocol in Java.
public static void main(String[] args) throws IOException {
try(Rcon rcon = Rcon.open("localhost", 25575)) {
if (rcon.authenticate("password")) {
System.out.println(rcon.sendCommand("list"));
} else {
System.out.println("Failed to authenticate");
}
}
}
Add to build.gradle
:
repositories {
mavenCentral()
}
dependencies {
implementation 'nl.vv32.rcon:rcon:1.2.0'
}
Add to pom.xml
:
<dependencies>
<dependency>
<groupId>nl.vv32.rcon</groupId>
<artifactId>rcon</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
If you're not using Gradle, you can download the latest version here.
By default (using Rcon.open
), the client uses the RCON protocol as described by the Source RCON Protocol.
By using RconBuilder
a couple of parameters can be changed:
- Read buffer capacity
- Write buffer capacity
- Packet payload encoding
Example:
try (Rcon rcon = Rcon.newBuilder()
.withChannel(SocketChannel.open(
new InetSocketAddress("localhost", 25575)))
.withCharset(StandardCharsets.UTF_8)
.withReadBufferCapacity(1234)
.withWriteBufferCapacity(1234)
.build()) {
...
}