Skip to content

UDP and RUDP communication library with ordered packet handling including Goodieutils

License

Notifications You must be signed in to change notification settings

iGoodie/jRUDP-with-Goodieutils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jRUDP-with-Goodieutils

A wrapper for Slaynash/jRUDP repository included Goodieutils. jRUDP is a Reliable Java UDP Library for multiplayer games and more.

Compile and run

Requirements

Examples:

public class Server {

	public static RUDPServer serverInstance;
	public static final int SERVER_PORT = 56448;
	public static void main(String[] args) {
		try {
			serverInstance = new RUDPServer(SERVER_PORT);
			serverInstance.setPacketHandler(OrderedPacketHandler.class);
			serverInstance.start();
		}
		catch(SocketException e) {
			ConsolePrinter.error("Port %d is occupied. Server couldn't be initialized.", SERVER_PORT);
			System.exit(-1);
		}

		//send data to every client
		for(RUDPClient c : serverInstance.getConnectedClients()) {
			c.sendPacket(new byte[]{0x00});
			c.sendReliablePacket(new byte[]{0x00});
		}

		serverInstance.kick("localhost", 1234); //kick localhost:1234
		serverInstance.stop();
	}
	
}
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 {
			client = new RUDPClient(SERVER_HOST, SERVER_PORT);
			client.setPacketHandler(OrderedPacketHandler.class);
			client.connect();
		}
		catch(SocketException e) {
			ConsolePrinter.error("Cannot allow port for the client. Client can't be launched.");
			System.exit(-1);
		}
		catch(UnknownHostException e) {
			ConsolePrinter.error("Unknown host: %s", SERVER_HOST);
			System.exit(-1);
		}
		catch(SocketTimeoutException e) {
			ConsolePrinter.error("Connection to %s:%d timed out.", SERVER_HOST, SERVER_PORT);
		}
		catch (InstantiationException e) {} //Given handler class can't be instantiated.
		catch (IllegalAccessException e) {} //Given handler class can't be accessed.
		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
	}
	
}

Getting support

If you have any question or you found a problem, you can;

About

UDP and RUDP communication library with ordered packet handling including Goodieutils

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%