diff --git a/README.md b/README.md index 7adc747..ce6f1d4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Reliable-UDP-library +# jRUDP A Reliable Java UDP Library for multiplayer games and more Specials thanks @@ -34,7 +34,7 @@ public class Server c.sendPacket(new byte[]{0x00}); c.sendReliablePacket(new byte[]{0x00}); } - + serverInstance.kick("localhost", 1234); //kick localhost:1234 serverInstance.stop(); } @@ -46,9 +46,9 @@ public class Client { public static final InetAddress SERVER_HOST = NetUtils.getInternetAdress("localhost"); public static final int SERVER_PORT = 56448; - + public static RUDPClient client; - + public static void main(String[] args) { try { @@ -67,13 +67,13 @@ public class Client catch(SocketTimeoutException e) { System.out.println("Connection to " + SERVER_HOST + ":" + SERVER_PORT + " timed out."); } - catch (InstantiationException e) {} //Given handler class can't be instantiated. + catch (InstantiationException e) {} //Given handler class can't be instantiated. catch (IllegalAccessException e) {} //Given handler class can't be accessed. - catch(IOException e) {} + catch(IOException e) {} client.sendPacket(new byte[]{0x00}); //Send packet to the server client.sendReliablePacket(new byte[]{0x00}); //Send packet to the server - + client.disconnect(); //Disconnect from server } } diff --git a/src/fr/slaynash/communication/rudp/RUDPClient.java b/src/fr/slaynash/communication/rudp/RUDPClient.java index 0ad838a..c6ea7ac 100644 --- a/src/fr/slaynash/communication/rudp/RUDPClient.java +++ b/src/fr/slaynash/communication/rudp/RUDPClient.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; @@ -109,6 +110,9 @@ public boolean isConnected() { } public void setPacketHandler(Class packetHandler){ + if(Modifier.isAbstract(packetHandler.getModifiers())) { //Class should not be abstract! + throw new IllegalArgumentException("Given handler class cannot be an abstract class!"); + } this.packetHandlerClass = packetHandler; } diff --git a/src/fr/slaynash/communication/rudp/RUDPServer.java b/src/fr/slaynash/communication/rudp/RUDPServer.java index 6d68cfd..e45455f 100644 --- a/src/fr/slaynash/communication/rudp/RUDPServer.java +++ b/src/fr/slaynash/communication/rudp/RUDPServer.java @@ -79,7 +79,7 @@ public void setPacketHandler(Class clientManager){ throw new IllegalArgumentException("Given handler class cannot be an abstract class!"); } - this.clientManager = clientManager; + this.clientManager = clientManager; } /* Actions */