Skip to content

AlexDerProGamer/PacketQuery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

PacketQuery

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

Add as Dependency

<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

Example Usage

Initialization

Server

Server server = PacketQuery.initServer(8000);

Client

Client client = PacketQuery.initClient("my client", 8000);

There can't be two clients connected with the same name

Packet Sending

Create a Packet

Packet packet = new PacketBuilder()
        .write("my.test.message")
        .write("Hello")
        .write("It's me! :D")
        .build();

Server

server.sendPacketToClient("my client", packet);

If the client is not connected/no client has the given name nothing will happen

Client

client.sendPacketToServer(packet);

Packet Handling

Server

@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());

Client

@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());

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages