GNetLib V0.0.0.3 (A Simple Java Networking Library)

yes i guess that the error can be in the lib , but in my game i implemented a lot of packets and when im playing the game in online mode they are a lot of packets sending and receiveing between server and clients , how can produce always the error this packet and not the other types of packets that i use?.

Thank you for response :slight_smile:

How often is the exception thrown? Is it for every packet or just occasionally?

i test all packets manually:

i move the player for test the position packet --no problem
i trow magic spells and trow arrows to test the enemyBullet packet – no problem
i test the weapon kick damage packet – after a lot of tries fails and throw exception.

The strange in my fail is that the system works well with a lot of conflictive packets , but in 1 fail throwing exception.

i dont know if can be the error but , can be that i put all info in 1 entry and the conversions of object can crash the object?

Thank u a lot :slight_smile:

Would you be able to post a snippet of how you send a weapon kick damage packet?

of course :slight_smile: :


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

I include in the packet the ID of the client who do damage(int) and the power of damage(int).
cliente is a clientGame object , that gives the clientModel class and listener.
servidorHost is a ServerModel that have the configuration of the server to send him packets.

ok people , i located the fail of my code , it seems that if server receive a packet , cant use the information of this packet and resent a copy of this packet to other clients , i modified the confictive packet to avoid this error and now dont crash the client , but i dont know how the lib cant resend a packet from a client to a other clients.

I’m Currently Testing your Library, and i prefer this to Kryonet for testing / understanding how networking goes. However, i like modular games, and as i was reading your source code, i noticed this your function :

public void addEventListener(final ClientEventListener clientEventListener) {
this.clientEventListener = clientEventListener;
}

i think it’s not correct to call this “add” since it’s a set. i’m wondering if you can build a system that forwards packets to multiple listeners, like :

addEventListener(new ChatListener());
addEventListener(new GameInputsListener());
addEventListener(new AnotherPluggedService());

then send a custom Packet that ChatListener can handle, it’s read by ChatListener, then consumed (pretty much like an event system ? :D)
if it’s a GameInputListener (e.g) then ChatListener just doesn’t handle it, and Packet is forwarded to GameInputsListener.

sorry for the bad English.
PS: That could be really awesome for plugins/modules for games using this library.

[quote]Customization of serialization
[/quote]
Kroynet does provide custom serialization: Here

But besides that this looks great!

hi people:

anyone tried to redirect from server a packet sended by one player to all players except him?.

I want to comunicate to the other players that i created a bullet , and when client game creates the bullet automatly send a packet to the server with coordinates of the bullet , the server have to redirect this packet to all players in server except player who sended the packet , i tried to do:


@Override
protected void packetReceived(ClientModel arg0, Packet arg1) {
if(arg1.getPacketName().equals("newBullet"))
	{
            Packet packet = new Packet("bullet",3);
            packet.addEntry("client",arg1.getEntry("client"));
            packet.addEntry("x",arg1.getEntry("posx"));
            packet.addEntry("y",arg1.getEntry("posy"));  
            server.sendToAllBut(arg0, packet);
	}
}




is simple but when i test with multiple tries the client crash with stream corrupted exception. code 00 or code 73

Is correct my way to comunicate from 1 client to others?

Thank you :slight_smile:

Networking can basically be like :

Client sends “i shoot”
Server (calculates the location / rotation of bullet)
Server broadcasts “created bullet @ (x,y,r)”
Client creates bullet

But this way the game will appear laggy for all the clients (try it on a multiplayer game on Age OF Empire II e.g.). The fact is that every single action for the player is going to be asserted by the server.
Facing this lag issue, the solution is to locally admit your action is valid. e.g :

Client creates bullet + sends “i shoot”
Server tests validity of the input/action
Server broadcasts everyone BUT THIS CLIENT “new bullet @ (x,y,r)” [this way action is valid]
OR
Server answers Client “delete this bullet” [this way, action is not valid]


I don’t know if there is an implementation of broadcasting on server, but my way to handle this would be in the ServerListenner class:


public class PersonnalListenner extends ServerEventListener {
			
	private List<ClientModel> clients = new List<ClientModel>();
	
	protected void packetReceived(ClientModel client, Packet packet) {
		
	}

	@Override
	protected void errorMessage(String msg) {
		
	}
	
	@Override
	protected void debugMessage(String msg) {
		
	}
	
	@Override
	protected void clientDisconnected(ClientModel client) {
		clients.remove(client);
	}
			
	@Override
	protected void clientConnected(ClientModel client) {
		clients.add(client);
	}
	
	public void broadcast(Packet p) {
		//sends the packet to each client connected
		for(ClientModel c : clients){
			c.sendPacket(p);
		}
	}
	
	public void broadcastExcepted(ClientModel excepted, Packet p) {
		for(ClientModel c : clients){
			if(c == excepted){
				continue; //skips the "broadcast" behaviour if ClientModel in param is encountered
			}
			c.sendPacket(p);
		}
	}
}

I didn’t try to run this code (i’m not working over this for now). Also think about synchronizing every piece of code arround accessing “clients” list.

Sorry for the bad english :P. I hope i’m understandable.

Well, now i posted this, i just realised some personnal issue.

Currently, i’m working on a multiplayer game, driven by entities. So everyone can instanciate Entities with an identifier.

Basically, the server is the only one that gives order of instanciation. SO every client updates their Entity list by creating the missing Entity with specified properties.

Now I explained that we could smooth the personnal lag by updating the game and noticing the server at the same time, this is now a matter of identifiers.

If you build things like this, clients can instanciate Entities without server’s permission, making possible conflicts between identifiers ! Any good idea ? :smiley:

Im thinking of giving up on kryonet and giving this a go xD

this is awesome it really helps!

Neat little library you have going here. I use LibGDX and gave it a try and it works fine on desktop, however when running it on Android it crashes. I didn’t spend any time on troubleshooting yet but what is your goal is it supposed to run on Android at all?

TehJavaDev (the OP) hasn’t been on this forum in 3 months, but I think I speak on their behalf that this library was meant to be only for Desktop. However, I have heard that KryoNet is quite good and runs on Android. You may want to look into that.

Thanks CopyableCougar, I did check the KryoNet and was able to move desktop over to it fairly quickly. It seems fairly similar in concept, I liked GNetLibs Packet concept but other than that it is definitely more mature and robust library. Haven’t tried the Android yet.

This actually looks quite interesting. I would love to resurrect this project if its dead. The ideas are actually quite neat. Depends on the OP though, I guess…

I don’t see a reason why you can’t fork the project and keep building upon it, as long as you give credit appropriately. It’s always nice to have competition and choice in terms of libraries and toolsets :slight_smile:

yeah, or just make a new project that is kinda similar to this so its easy to send and receive packets! :slight_smile:

What happened to OP? This project could have went somewhere… :frowning: :frowning: