GNetLib V0.0.0.3 (A Simple Java Networking Library)

i sent you msg and stuff!
please add me on skype and help me with this networking
i will all credits to you throw my youtube channel when i
do tutorials
all i want to learn is how to get the clients to see etch other and see etch other
move after that i have learned that and it will be easyer for me to understands this packet things
:slight_smile: ty

Skype: tomastero

The ClientShutdownPacket has been pre-programmed into the library: (Meaning you do not need to create/add data entry’s to it)


// Pre-programmed packet: org.gnet.packet.ClientShutdownPacket class
public ClientShutdownPacket() {
	super("ClientShutdownPacket", 1);
	super.addEntry("shutdownClient", Boolean.TRUE);
}

You’ll need to revise your code like so: (Note line 15 on how to properly send the packet/handle packet events)


if (packet.getPacketName().equals("UserPacket")) {
	users.add((String) packet.getEntry("username"));
	String test = users.get(0);
	System.out.println(packet.getEntry("IP"));

	boolean kick = in.nextLine().contains("kick: ");
	if (kick) {
		String[] x = in.nextLine().split(":", -1);
		System.out.println(x[0]);
		System.out.println(x[1]);

		// HERE: Send the packet to disconnect the client.
		client.sendPacket(new ClientShutdownPacket());
		return; // packet handled.
	} else if (!kick) {
		// If you've received the packet, and kick = false, still 'return'.
		return; // packet handled.
	} 
}

You’re welcome :slight_smile:
Would be a nice feature to have also @BurntPizza/robocos.

Very easy process, I’ll try and help you within the next few days when I get some free time as you’ve made a YouTube video for me already which is greatly appreciated <3

Added both of you :slight_smile:

But still, how do I kick a client individually without having to kick all the clients?

put players that you want to kick in hashmap or arraylist
then get ex

name
id
Player
and then kick all players in that arraylist or hashmap

Can you elaborate on this?
(Possible bug?)

Basically you would do what VirtueeL suggested:

  • Create some sort of List that will be used to store the players.
  • Each time a player connects add him to the list. (vice-versa for disconnecting)

You now have control over any client on the list.

V0.0.0.3 is finally here, decided to completely re-write it again and have fixed/added a few things.

Sorry I couldn’t fit in UDP in this update. :cranky:

V0.0.0.3 will include:
I’ve added support for obtaining debug/error messages - As requested by robocos987
I’ve added a ServerMonitor GUI. (Advanced statistics)
Fixed all memory leaks/non functional events/variables.
A re-written event handling system.
A functional ClientShutdownPacket to kick individual clients.
Each client that connects now has their own generated UID.

Download link: Download GNetLib.jar
New code required to create the server: view pastebin
New code required to create the client: view pastebin

I will add a tutorial to the OP on how to set up a server/client along with handle events and enable the new ServerMonitor.
EDIT: Done, also uploaded V0.0.0.3 source into OP.

I’ve decided to keep track of project bugs in the OP :slight_smile: (Now visible with fix dates)

  • On another note, I’m making a multiplayer demo game with GNetLib XD (Client/Server)

EDIT: During my progress of the multiplayer demo I added these methods in the demo than thought… why doesn’t the server have these? lol ::).

Update to GNetServer class: (OP download links have been updated to include this update)


public void sendToAll(Packet packet); // Send to ALL online clients
public void sendToAllBut(ClientModel who2NotSend2, Packet packet); // Send to ALL besides 'who2NotSend2'

thats a really good function for sending movement and other stuff like msg to all players
really good! keep up bruh! cant wait for the demo =D

when is the demo coming =D

Thanks for asking :slight_smile:

Hopefully within the next week, I’m rather busy with appointments and such at the moment :confused:

Demo has been started :smiley: and core functions are working, just need to implement a few more things before release :slight_smile:

Demo will include:
A multiplayer server along with a client.
Clients will be able to see all other online clients at their current position along with their UID above their head.
(As demo will not include a registration/login system so no usernames yet :P)
Clients will be able to click a client in the game world and have the option to PM them.
Maybe a public chat system :slight_smile:

Any other suggestions for what to include in the demo that GNetLib offers?

Just had to interrupt my development of this demo to post, as this is my first multiplayer game ever.
(And it’s using my own networking library which is also my first, so WOOT XD) :point: :point:

What the demo now contains:
You can see every player as they join the server. (Initial location)
You can see every player as they move and vice-versa for you. (Current location)
You can see every players UID above their head. (No username implementation in demo)

Here’s a YouTube video of the multiplayer demo brought to you by your very own JGO user VIrtueeL:
(If the video is too small in this thread: Watch on YouTube in HD/fullscreen -> leave a like & comment / sub if you wish ::))

bXU_pvAXUIs

NOTE: Demo still has a few minor glitches that need to be fixed before being posted :slight_smile:

New updates to GNetLib:
You no longer have to enable the ServerMonitor prior to starting the server.
(As before when server.start() was called it would initialize / show the ServerMonitor)
You no longer have to do this, you can now enable/disable the ServerMonitor on the fly. :smiley:

I’ve also changed the length of the generated UID for each client to 4. (Think it was 9 before?)
In future updates I’ll enable the ability for the user to decide the length of the UID the server generates for each client.

New methods in GNetServer class:


// Will initialize and show ServerMonitor.
public void enableServerMonitor();

// Will dispose of ServerMonitor.
public void disableServerMonitor();

Also added a Boolean to GNetServer class to keep track of whether or not the ServerMonitor is visible:


public boolean isServerMonitorVisible();

ON ANOTHER IMPORTANT NOTE:
I accidentally deleted the multiplayer demo from my eclipse workspace…
Totally wasn’t thinking, so I’ll be re-writing the demo and it will be more cleaner/faster/graphically enticing.

Sorry development’s been paused, dealing with medical issues IRL at the moment.

Just figured I’d let people know :slight_smile:

i still have the demo if you want it?

Hello people ,

I’m Focan and im a programmer with games development hobby :slight_smile:

Im programming a game with libgdx libraries and i finished the single player mode , last weekend i started to program the multiplayer mode with gnet library , but i have a lot of problems with this library.

i can’t send packets from client to server unless server sends a packet to a client , i can’t send packets manually from client to server?.

i generated a loop between client and server , generating packets to update player coordinates in server and server responds asking again for new coordinates , it works but the memory consumition is too hight and sends too much packets per frame , how i can slow down this loop?.

Sorry for my english… :frowning:

And thank you for answers. :slight_smile:

fixed timestep then only send 1 packet with the players movement every 60f
then callucultate what direction hes traveling or something =/

dont send so manny packets at the same time its rly bad =D

MMOs send about up to 10 packets a second for position changes. Don’t remember where I read this.

Hi people , im in a little trouble with gnet lib , im getting the errors

StreamCorruptedException: invalid type code: 73

StreamCorruptedException: invalid type code: 00

and the error is getting at lines 92 and 49 of GnetClient.java class

In the client Side where im passing this packet:

Packet paquete = new Packet(“jugadorTocado”, 1);
paquete.addEntry(“valor”,cliente.otherPlayers.get(i).clientId +":"+ melePj.power );
cliente.servidorHost.sendPacket(paquete);

i tract the packet in the server like this:


if(arg1.getPacketName().equals("jugadorTocado"))
			{
				for(int i =0; i < server.getClients().size(); i++) // i send the packet to all the clients , i tryed with SendToAll() function but got same error
				{
					try
					{
						if(server.getClients().get(i).getUuid() == Integer.valueOf(String.valueOf(arg1.getEntry("valor")).split(":")[0]))
					{
						Packet paquete= new Packet("jugadorTocado", 1);
						paquete.addEntry("valor", arg1.getEntry("valor"));
						server.getClients().get(i).sendPacket(paquete);
					}
					}
					catch(NullPointerException e)
					{
						System.out.print("error null pointer en reenvio de paquete de daño de player a otros players");
					}
					catch(IndexOutOfBoundsException e)
					{
						System.out.print("error out of bounds en reenvio de paquete de daño de player a otros players");
					}
							
				}
			}

and when i recieve it from other player i tract like this


int lifeDept;

 if(arg1.getPacketName().equals("jugadorTocado"))
	{
		try
		{
						lifeDept+= Integer.valueOf(String.valueOf(arg1.getEntry("valor")).split(":")[1]);
		}
		catch (NumberFormatException e)
		{
		lifeDept=0;
			System.out.print("\n error de parseado de daño de player enemigo");
		}
	}

Something wrong in my code?

I believe those errors are related to serialization. The serialization over a network may be causing issues if serial version ids and actual class data doesn’t match up.

I browsed through GNetLib and all packets are serialized across the network, which means that the serialization is the library’s job, so I don’t think you did anything wrong in your code but I’m not sure.