Hi,
I'm trying to code a simple client/server using KryoNet but I'm struggling with something, my client can't receive packets while sending.
When I hold the right key I want my player to move 1pixel to the right. In my situation when I hold the right key my player moves 1 pixel to the right, then stop moving, and finally when I release the key he literally teleports himself in the right direction. I other words the client receive almost all the packets at one time.
Here's my code:
Client:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public void launch() throws SlickException, IOException { AppGameContainer container = new AppGameContainer(this); container.setMinimumLogicUpdateInterval(10); container.setMaximumLogicUpdateInterval(10); container.setUpdateOnlyWhenVisible(false); container.setAlwaysRender(true);
client = new Client(); ClassRegister.register(client.getKryo()); client.addListener(new CustomListener(this));
client.start();
if (!connected) { Log.set(Log.LEVEL_TRACE); try { client.connect(5000, host, port); connected = true; } catch (IOException e) { e.printStackTrace(); } } container.start(); } |
CustomListener:
1 2 3 4 5 6 7 8
| @Override public void received (Connection connection, Object object) { if (object instanceof MoveResponse) { MoveResponse response = (MoveResponse) object; getPlayer().move(response.dir); } } |
Server:
1 2 3 4 5 6 7 8
| private void start() throws IOException { server = new Server(); ClassRegister.register(server.getKryo()); server.bind(port); server.addListener(new ServerListener(this)); server.start(); Log.set(Log.LEVEL_TRACE); } |
ServerListener:
1 2 3 4 5 6 7 8 9 10
| @Override public void received(Connection connection, Object object) { if (object instanceof MoveRequest) { MoveRequest request = (MoveRequest) object; MoveResponse response = new MoveResponse(); response.dir = request.dir; connection.sendTCP(response); } } |
Input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public void update() { movePlayer(); }
private void movePlayer() { if (pressedRight) { sendMoveRequest(3); } else if (pressedUp) { sendMoveRequest(1); } else if (pressedDown) { sendMoveRequest(2); } else if (pressedLeft) { sendMoveRequest(4); } }
public void keyPressed(int key, char c) { if(key == goDown) { pressedDown = true; } else if(key == goLeft) { pressedLeft = true; } else if(key == goUp) { pressedUp = true; } else if(key == goRight) { pressedRight = true; } }
public void keyReleased(int key, char c) { if(key == goDown) { pressedDown = false; } else if(key == goLeft) { pressedLeft = false; } else if(key == goUp) { pressedUp = false; } else if(key == goRight) { pressedRight = false; } } |
I seriously don't see where I'm messing up

Any help?