Lag when sending position data

So what am I doing is sending the position of the player every time he moves


public void update() {
		int h = player.health;
		int mh = player.maxHealth;
		float xx = player.x;
		float yy = player.y;
		player.tick();
		if ((xx != player.x || yy != player.y) && ticks) {
			client.getServerConnection().sendUdp(new PacketPos(PlayerID, player.x, player.y));
		}
		if (h != player.health || mh != player.maxHealth) {
			client.getServerConnection().sendUdp(new PacketHealth(player.health, player.maxHealth));
		}
		ticks++;
	}

and my server sends the data to other clients


	public void received(Connection con, Object obj) {
	if (obj instanceof PacketPos) {
			for (Player p : ps) {
				Connection c = p.CON;
				if (c.getId() != con.getId()) {
					c.sendUdp(obj);
				}
			}
		}
	}

and then my clients receives that packet and moves the player with that id


	public void received(Connection con, Object obj) {
		if (obj instanceof PacketPos) {
			PacketPos pos = (PacketPos) obj;
			if(!hasID(pos)){
				con.sendTcp(new PacketReqReg(pos.id)); // if it cant recognize the id, it requests registration packet
			}
		}
	}
	
	public boolean hasID(PacketPos pos){
		for (PlayerOnline po : gclient.po) {
			if (po.id == pos.id) {
				po.posMove(pos.x, pos.y); // moves the player
				return true;
			}
		}
		return false;
	}

It is kinda working fine when there are 2 clients, when there are 3 it starts to drop the fps.

How do I optimize that and make the movement smooth?

I have tried to make it send the pos packet every few milisec but it looks chunky…

BTW: I use NitroNet

I suggest you do all your networking on a separate thread that’s not linked to rendering nor logic. This will probably remove the fps drop.

Also, instead of trying to send more packets to make it smoother, you’ll have to do some interpolation (and possibly extrapolation) of the positions. That is, you’ll smoothly move the entity from its old position to the new one over a series of frames to appear smooth.

Manage the state of the game server side and send an updated blob of state of the game to the clients at set intervals instead. Also you can interpolate between the most recent and second most recent states client side to achieve “smooth” looking movement.

http://www.gabrielgambetta.com/fast_paced_multiplayer.html