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.