Kryonet - one listener, two connections - one is somehow performing slower.

Hello guys! I won’t post all of the code, I will just write an example, cause it is too big and wouldn’t be useful.
I’m facing a strange problem since yesterday. I am implementing my own reliable UDP, sending lists of packets, clearing history of packets, doesn’t matter.

I have two Clients (their code is identical) with one exception - one is starting on the left side, one on the right side of the board. It has nothing to do with packets later.

Also, I have a Server with a gameroom where I pass these two players when they both connect:



public Character player_left, player_right;
public Connection pleft_connection, pright_connection;
public Listener gameRoomListener;

public GameRoom(Connection pleft, Connection pright) { 
		setName("GAMEROOM");
		player_left = new Character(1);
		player_right = new Character(2);
		this.pleft_connection = pleft;
		this.pright_connection = pright;
		addListeners();
		
		
		System.out.println("Sending who is starting left...");
		
		CasualGameReady out = new CasualGameReady();
		out.startingLeft = true;
		pleft_connection.sendTCP(out);
		out.startingLeft = false;
		pright_connection.sendTCP(out);

	}

As you can see above, I pass two connections and assing them to new ones, to use them in the Gameroom.
Next, we call ‘addListener()’ method which adds a listener to these connections:

public void addListener(){
		
		gameRoomListener = new Listener() 
		{
			public void received (Connection c, Object object)
			{
				
				if(c.equals(pleft_connection)){
					
					if(object instanceof RequestUnlockingControllers)
						setLeftReady();
					
					if(object instanceof someObject)
						player_left.doBlahblahblah();
				
					
				}else if(c.equals(pright_connection)){
					
					if(object instanceof RequestUnlockingControllers)
						setLeftReady();
					
					if(object instanceof someObject)
						player_right.doBlahblahblah();
			
			}
			
			public void disconnected (Connection c)
			{
				
			}
		};
		
	
		pleft_connection.addListener(gameRoomListener);
		pright_connection.addListener(gameRoomListener);
	}

I connect two clients from the same PC to the server on the same PC. I use LAN IP address, to force the client to connect with a router and come back.

So both clients connect with ‘192.168.1.2’.
Everything is okay and everything is working really fine with one exception:
one of the connections is slower!

I have some methods, which send player positions in lists and server gives back an info:
‘you can delete positions with sequence number lower than x, they are not needed anymore’.

And somehow, one ‘history list of packets’ is still 2-5 units bigger (one connection is processing slower), than second. Randomly, once left client, once right.
The only solution (cause I have tested ALL) is that server is slower on one of these two connections.
It is impossible, that the client causes the errors, cause both clients are IDENTICAL - they have same code.
Same thing on the server, both:
if(c.equals(pleft_connection))
if(c.equals(pright_connection))
blocks are identical - with only one keyword changed in every statement (player_left to player_right and vice versa).
Both objects player_left and player_right are also identical so it has to be the listener/connection fault.

Is the code above with attaching listeners, connections etc. correct? Or maybe there is a noobish mistake?
Cause if it is correct, bug has to be somewhere in the code.
If someone has any thoughts, ideas - I will take everyhing.

Thank you very much.

You could create two separate listeners for cheaphax.
Have you tried printing the connections and see if they print the same?

I support SuperMarios suggestion:
Try splitting up your listener in two listeners so that they are separate objects, this will also eliminate the need for those if statements which determine the connection.


public void addListener(){
      gameRoomListener_pleft = new Listener(){
            public void received (Connection c, Object object)
            {
                  if(object instanceof RequestUnlockingControllers)
                        setLeftReady();
                  if(object instanceof someObject)
                        player_left.doBlahblahblah();
            };
      };

      gameRoomListener_pright = new Listener(){
            public void received (Connection c, Object object)
            {
                  if(object instanceof RequestUnlockingControllers)
                        setRightReady();
                  if(object instanceof someObject)
                        player_right.doBlahblahblah();
            };
      };
   
      pleft_connection.addListener(gameRoomListener_pleft);
      pright_connection.addListener(gameRoomListener_pright);
   }

Still nothing, tried that before, now too.

Guys, is this possible that packets are being consumed by a random client?

Cause I have these both clients on one PC, server is also on the same PC.
I have tried printing the connections, they are ‘different’ and c1 is not equal to c2.

But maybe server doesn’t recognize them, I mean - packets are being sent to the router and he sends them back to 192.168.1.2 (where two clients are).
Maybe they are mixing somehow and that’s why left client is getting more packets than right client?

Odds are it is a simple bug in your own code. Just to reassure yourself: put the client ID in your packet explicitly, and you will see that each client only receives 1 distinct ID value.

Code bug, a week of searching for it, but what a victory!
This is freaking hard, but what a lesson :v

Thanks guys!