A simple event driven Netty based messaging API that sends messages through custom packet objects written in Java 21.
These packets are serialized and deserialized using Jackson.
Uses TinyLog for logging messages.
Note: Only localhost connections are supported Requires Java 21
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.alexderprogamer</groupId>
<artifactId>packetquery</artifactId>
<version>version</version>
</dependency>
Get the latest version here
Server server = PacketQuery.initServer(8000);
Client client = PacketQuery.initClient("my client", 8000);
There can't be two clients connected with the same name
Packet packet = new PacketBuilder()
.write("my.test.message")
.write("Hello")
.write("It's me! :D")
.build();
server.sendPacketToClient("my client", packet);
If the client is not connected/no client has the given name nothing will happen
client.sendPacketToServer(packet);
@Override
public void onClientMessageReceive(String clientName, Packet packet) {
String channel = packet.read();
if(channel.equals("my.test.message")){
String message = packet.read();
String message2 = packet.read();
System.out.println(clientName + ": " + message + ", " + message2);
}
}
The class needs to implement ClientPacketMessageEvent
PacketQuery.addClientMessageListener(new ClientPacketMessageListener());
@Override
public void onServerMessageReceive(Packet packet) {
String channel = packet.read();
if(channel.equals("my.test.message")){
String message = packet.read();
String message2 = packet.read();
System.out.println("Server: " + message + ", " + message2);
}
}
The class needs to implement ServerPacketMessageEvent
PacketQuery.addServerMessageListener(new ServerPacketMessageListener());