Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import com.github.simplenet.Client;
- import com.github.simplenet.Server;
- import com.github.simplenet.packet.Packet;
- public class BugSimpleNet {
- public static void main(String[] args){
- // Instantiate a new server.
- var server = new Server();
- Packet cached = Packet.builder().putByte(1);
- // Register one connection listener.
- server.onConnect(client -> {
- System.out.println(client + " has connected!");
- cached.queueAndFlush(client);
- cached.queueAndFlush(client);
- // Register a pre-disconnection listener.
- client.preDisconnect(() -> System.out.println(client + " is about to disconnect!"));
- // Register a post-disconnection listener.
- client.postDisconnect(() -> System.out.println(client + " has successfully disconnected!"));
- });
- // Bind the server to an address and port AFTER registering listeners.
- server.bind("localhost", 43594);
- // Instantiate a new client.
- var client = new Client();
- // Register a connection listener.
- client.onConnect(() -> {
- System.out.println(client + " has connected to the server!");
- client.readByte(System.out::println);
- // Builds a packet and sends it to the server immediately.
- Packet.builder().putByte(1).putInt(42).queueAndFlush(client);
- });
- client.connect("localhost", 43594);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement