Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package test;
  2.  
  3. import com.github.simplenet.Client;
  4. import com.github.simplenet.Server;
  5. import com.github.simplenet.packet.Packet;
  6.  
  7. public class BugSimpleNet {
  8.  
  9.     public static void main(String[] args){
  10.         // Instantiate a new server.
  11.         var server = new Server();
  12.         Packet cached = Packet.builder().putByte(1);
  13. // Register one connection listener.
  14.         server.onConnect(client -> {
  15.             System.out.println(client + " has connected!");
  16.             cached.queueAndFlush(client);
  17.             cached.queueAndFlush(client);
  18.  
  19.             // Register a pre-disconnection listener.
  20.             client.preDisconnect(() -> System.out.println(client + " is about to disconnect!"));
  21.  
  22.             // Register a post-disconnection listener.
  23.             client.postDisconnect(() -> System.out.println(client + " has successfully disconnected!"));
  24.         });
  25.  
  26. // Bind the server to an address and port AFTER registering listeners.
  27.         server.bind("localhost", 43594);
  28.  
  29.  
  30.         // Instantiate a new client.
  31.         var client = new Client();
  32.  
  33. // Register a connection listener.
  34.         client.onConnect(() -> {
  35.             System.out.println(client + " has connected to the server!");
  36.  
  37.             client.readByte(System.out::println);
  38.  
  39.             // Builds a packet and sends it to the server immediately.
  40.             Packet.builder().putByte(1).putInt(42).queueAndFlush(client);
  41.         });
  42.  
  43.         client.connect("localhost", 43594);
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement