Skip to content

Commit

Permalink
Checking if the PacketHandler class passed to rudpclient is abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
Slaynash committed Mar 4, 2018
1 parent 6441337 commit e575af0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reliable-UDP-library
# jRUDP
A Reliable Java UDP Library for multiplayer games and more

Specials thanks
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/fr/slaynash/communication/rudp/RUDPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +110,9 @@ public boolean isConnected() {
}

public void setPacketHandler(Class<? extends PacketHandler> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fr/slaynash/communication/rudp/RUDPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void setPacketHandler(Class<? extends PacketHandler> clientManager){
throw new IllegalArgumentException("Given handler class cannot be an abstract class!");
}

this.clientManager = clientManager;
this.clientManager = clientManager;
}

/* Actions */
Expand Down

0 comments on commit e575af0

Please sign in to comment.