Charset Handling
Purpose
Understanding how Rcon handles character encoding for commands and responses, especially for Minecraft color codes.
Overview
RCON is fundamentally a binary protocol, but text payloads are encoded as byte arrays. The choice of character encoding affects how color codes and special characters are preserved.
Default Encoding: UTF-8
UTF-8 is the default encoding for all text:
RconClient client = RconClient.builder()
.host("localhost")
.port(25575)
.password("password")
// UTF-8 is default
.build();UTF-8 works correctly for: * Standard ASCII text * Unicode characters (emoji, international characters) * Most command output
Color Code Encoding: ISO-8859-1
Minecraft uses section signs (§) for color codes. These color codes are not standard ASCII and require special handling.
Example: Color Code Preservation
// With UTF-8 (default)
RconClient utf8Client = RconClient.builder()
.host("localhost")
.port(25575)
.password("password")
.build();
RconResponse response = utf8Client.sendCommand("list");
System.out.println(response.getResponse());
// Output: ??c[Server] ??fOnline players: 3
// Color codes are corrupted!
// With ISO-8859-1
RconClient latin1Client = RconClient.builder()
.host("localhost")
.port(25575)
.password("password")
.charset(StandardCharsets.ISO_8859_1)
.build();
RconResponse response = latin1Client.sendCommand("list");
System.out.println(response.getResponse());
// Output: §c[Server] §fOnline players: 3
// Color codes are preserved!Minecraft Color Codes
Standard Minecraft color codes:
| Code | Color | Name |
|---|---|---|
| Black | BLACK |
| Dark Blue | DARK_BLUE |
| Dark Green | DARK_GREEN |
| Dark Aqua | DARK_AQUA |
| Dark Red | DARK_RED |
| Dark Purple | DARK_PURPLE |
| Gold | GOLD |
| Gray | GRAY |
| Dark Gray | DARK_GRAY |
| Blue | BLUE |
| Green | GREEN |
| Aqua | AQUA |
| Red | RED |
| Light Purple | LIGHT_PURPLE |
| Yellow | YELLOW |
| White | WHITE |
Formatting codes:
| Code | Effect | Name |
|---|---|---|
| Obfuscated | MAGIC |
| Bold | BOLD |
| Strikethrough | STRIKETHROUGH |
| Underline | UNDERLINE |
| Italic | ITALIC |
| Reset | RESET |
When to Use Each Encoding
Use UTF-8 (Default) When:
-
You don’t need color codes
-
Working with international characters
-
Processing log files
-
Using modern Minecraft versions without color codes
RconClient client = RconClient.builder()
.host("localhost")
.port(25575)
.password("password")
// UTF-8 is default, no need to specify
.build();Use ISO-8859-1 When:
-
You need to preserve Minecraft color codes
-
Processing chat messages with formatting
-
Parsing server responses with
§codes -
Working with legacy Minecraft versions
RconClient client = RconClient.builder()
.host("localhost")
.port(25575)
.password("password")
.charset(StandardCharsets.ISO_8859_1)
.build();Encoding Comparison
String text = "§c[Server] §fWelcome!";
// UTF-8 encoding
byte[] utf8 = text.getBytes(StandardCharsets.UTF_8);
// Result: C2 A7 63 5B 53 65 72 76 65 72 5D 20 C2 A7 66 57 65 6C 63 6F 6D 65 21
// ISO-8859-1 encoding
byte[] latin1 = text.getBytes(StandardCharsets.ISO_8859_1);
// Result: A7 63 5B 53 65 72 76 65 72 5D 20 A7 66 57 65 6C 63 6F 6D 65 21
// UTF-8 uses 2 bytes for § (C2 A7)
// ISO-8859-1 uses 1 byte for § (A7)Strip Color Codes
If you don’t need color codes, strip them for cleaner output:
public static String stripColorCodes(String input) {
return input.replaceAll("§[0-9a-fk-or]", "");
}
String response = client.sendCommand("list").getResponse();
String cleanResponse = stripColorCodes(response);
System.out.println(cleanResponse);
// Output: [Server] Online players: 3Performance Notes
-
ISO-8859-1 is slightly faster than UTF-8 (single-byte encoding)
-
Both are hardware-accelerated on modern JVMs
-
Performance difference is negligible for typical RCON usage
See Also
-
Packet Protocol - Binary packet structure
-
Common Configurations - Client setup examples
-
Protocol Specification - Complete protocol docs