File tree Expand file tree Collapse file tree
src/main/java/xyz/synse/packetnet Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,12 +24,12 @@ private static final String secretKey = "1F16hIQ3SjQ$k1!9";
2424
2525public static void main(String [] args) throws Exception {
2626 // Create and start the server
27- Server server = new Server (1024 );
27+ Server server = new Server ();
2828 server. addListener(createServerListener());
2929 server. start(3300 , 3301 );
3030
3131 // Create and connect the client to the server
32- Client client = new Client (1024 );
32+ Client client = new Client ();
3333 client. addListener(createClientListener());
3434 client. connect(" 127.0.0.1" , 3300 , 3301 );
3535
Original file line number Diff line number Diff line change 66
77 <groupId >xyz.synse</groupId >
88 <artifactId >PacketNet</artifactId >
9- <version >1.3</version >
9+ <version >1.3.1 </version >
1010
1111 <properties >
1212 <maven .compiler.source>20</maven .compiler.source>
Original file line number Diff line number Diff line change @@ -22,12 +22,12 @@ public class Test {
2222
2323 public static void main (String [] args ) throws Exception {
2424 // Create and start the server
25- Server server = new Server (1024 );
25+ Server server = new Server ();
2626 server .addListener (createServerListener ());
2727 server .start (3300 , 3301 );
2828
2929 // Create and connect the client to the server
30- Client client = new Client (1024 );
30+ Client client = new Client ();
3131 client .addListener (createClientListener ());
3232 client .connect ("127.0.0.1" , 3300 , 3301 );
3333
Original file line number Diff line number Diff line change @@ -22,10 +22,22 @@ public class Client {
2222 private Thread tcpThread ;
2323 private Thread udpThread ;
2424
25+ /**
26+ * Creates a new instance of the Client class.
27+ *
28+ * @param bufferSize The size of the buffer for receiving data.
29+ */
2530 public Client (int bufferSize ) {
2631 this .bufferSize = bufferSize ;
2732 }
2833
34+ /**
35+ * Creates a new instance of the Client class with buffer size of 8192 bytes.
36+ */
37+ public Client () {
38+ this (8192 );
39+ }
40+
2941 /**
3042 * Connects the client to the server using the specified TCP and UDP ports.
3143 *
Original file line number Diff line number Diff line change 11package xyz .synse .packetnet .common .compression ;
22
3+ import xyz .synse .packetnet .common .compression .compressors .DeflaterCompressor ;
34import xyz .synse .packetnet .common .compression .compressors .GZipCompressor ;
45import xyz .synse .packetnet .common .compression .compressors .LZ4Compressor ;
56import xyz .synse .packetnet .common .packets .Packet ;
67
78import java .io .IOException ;
89
910public class PacketCompressor {
11+ public static final ICompressor DEFLATER_COMPRESSOR = new DeflaterCompressor ();
1012 public static final ICompressor GZIP_COMPRESSOR = new GZipCompressor ();
1113 public static final ICompressor LZ4_COMPRESSOR = new LZ4Compressor ();
1214
Original file line number Diff line number Diff line change 1+ package xyz .synse .packetnet .common .compression .compressors ;
2+
3+ import xyz .synse .packetnet .common .compression .ICompressor ;
4+
5+ import java .io .ByteArrayOutputStream ;
6+ import java .io .IOException ;
7+ import java .util .zip .DeflaterOutputStream ;
8+ import java .util .zip .InflaterOutputStream ;
9+
10+ public class DeflaterCompressor implements ICompressor {
11+ @ Override
12+ public byte [] compress (byte [] in ) throws IOException {
13+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
14+ DeflaterOutputStream defl = new DeflaterOutputStream (out );
15+ defl .write (in );
16+ defl .flush ();
17+ defl .close ();
18+
19+ return out .toByteArray ();
20+ }
21+
22+ @ Override
23+ public byte [] decompress (byte [] in ) throws IOException {
24+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
25+ InflaterOutputStream infl = new InflaterOutputStream (out );
26+ infl .write (in );
27+ infl .flush ();
28+ infl .close ();
29+
30+ return out .toByteArray ();
31+ }
32+ }
Original file line number Diff line number Diff line change 77
88public class PacketBuilder implements AutoCloseable {
99 private final short id ;
10- private final ByteArrayOutputStream byteOut = new ByteArrayOutputStream () ;
11- private final DataOutputStream out = new DataOutputStream ( byteOut ) ;
10+ private final ByteArrayOutputStream byteOut ;
11+ private final DataOutputStream out ;
1212
1313 public PacketBuilder (short id ) {
1414 this .id = id ;
15+ this .byteOut = new ByteArrayOutputStream ();
16+ this .out = new DataOutputStream (byteOut );
1517 }
1618
1719 public PacketBuilder withBytes (byte [] data ) {
Original file line number Diff line number Diff line change @@ -32,6 +32,13 @@ public Server(int bufferSize) {
3232 running = false ;
3333 }
3434
35+ /**
36+ * Creates a new instance of the Server class with buffer size of 8192 bytes.
37+ */
38+ public Server () {
39+ this (8192 );
40+ }
41+
3542 /**
3643 * Starts the server on the specified TCP and UDP ports.
3744 *
You can’t perform that action at this time.
0 commit comments