More Kryonet issues Buffer overflow

My game works perfectly fine and i have tried looking up this issue put but cant find any info on it but this is the error im getting;


Exception in thread "Thread-0" com.esotericsoftware.kryo.KryoException: Buffer overflow. Available: 0, required: 1
	at com.esotericsoftware.kryo.io.ByteBufferOutput.require(ByteBufferOutput.java:189)
	at com.esotericsoftware.kryo.io.ByteBufferOutput.writeByte(ByteBufferOutput.java:261)
	at com.esotericsoftware.kryo.io.ByteBufferOutput.writeVarInt(ByteBufferOutput.java:316)
	at com.esotericsoftware.kryo.io.ByteBufferOutput.writeInt(ByteBufferOutput.java:301)
	at com.esotericsoftware.kryo.serializers.UnsafeCacheFields$UnsafeIntField.write(UnsafeCacheFields.java:39)
	at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:449)
	at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:602)
	at com.esotericsoftware.kryonet.KryoSerialization.write(KryoSerialization.java:66)
	at com.esotericsoftware.kryonet.TcpConnection.send(TcpConnection.java:210)
	at com.esotericsoftware.kryonet.Connection.sendTCP(Connection.java:77)
	at com.horizon.game.map.MapData.pullChunkFromServer(MapData.java:1026)
	at com.horizon.game.map.MapData.requestChunk(MapData.java:935)
	at com.horizon.game.map.MapData.getChunk(MapData.java:219)
	at com.horizon.game.map.MapData.getTile(MapData.java:533)
	at com.horizon.game.map.MapData.stitchMap(MapData.java:770)
	at com.horizon.game.map.MiniMap.updateMap(MiniMap.java:35)
	at com.horizon.game.horizon.tick(horizon.java:155)
	at com.horizon.game.horizon.run(horizon.java:107)
	at java.lang.Thread.run(Thread.java:745)

anyone have any clue

Side note: This error only accures when im connecting to my server from another computer, when im running using localhost it works fine

Can you post some code? Most likely you need to increase the buffer size in the constructor of the client.

Also, how did you misspell “tried” and “using”? Not trying to be offensive, just trying to point out your spelling mistakes since you said you have trouble with spelling!

Im always working at night so my spelling goes out the window and this is my client constructor, also i have never set a buffer size, have not known how too, so that might be whats up


public class GameConnection {
	private Client client;
	public GameConnection(Level level,horizon horizon,String url,boolean isPinging,int worldID,String portTCP,String portUDP) {
		client = new Client();
		registerPackets();
		ClientNetworkListiner nl = new ClientNetworkListiner(level);
		nl.init(client,horizon,url,portTCP,portUDP);
		client.addListener(nl);
		client.start();
		try {
			client.connect(5000, url, Integer.parseInt(portTCP),Integer.parseInt(portUDP));
			if(!isPinging){
				client.sendTCP(new Packet0HandshakeRequest());
			}
		} catch (IOException e1) {
			System.out.println("Unable to find server!");
			if(!isPinging){
				
			}else{
				horizon.MultiplayerMenu.setCurrentPlayers(worldID, 0);
				horizon.MultiplayerMenu.setMaxPlayers(worldID, 0);
				horizon.MultiplayerMenu.setServerName(worldID, "Cannot find server!");
				horizon.MultiplayerMenu.setWorldIDs(worldID, worldID);
				horizon.MultiplayerMenu.setServerIP(worldID, url);
				horizon.MultiplayerMenu.setServerPortTCP(worldID, portTCP);
				horizon.MultiplayerMenu.setServerPortUDP(worldID, portUDP);
			}
		}
	}
	public void sendChat(String chat){
		Packet10SimpleMessage message = new Packet10SimpleMessage();
		message.message = chat;
		horizon.getGame().getConnection().getClient().sendTCP(message);
	}
	private void registerPackets(){
		Kryo kryo = client.getKryo();
		kryo.register(Packet0HandshakeRequest.class);
		kryo.register(Packet1HandshakeAnswer.class);
		kryo.register(Packet2ServerAlive.class);
		kryo.register(Packet3ServerAliveConfirmation.class);
		kryo.register(Packet4PullServerInfo.class);
		kryo.register(Packet5ServerPatrol.class);
		kryo.register(Packet6SendPlayerInfo.class);
		kryo.register(Packet7AcceptedPlayer.class);
		kryo.register(Packet8KeepConnectionAlive.class);
		kryo.register(Packet9KickPlayer.class);
		kryo.register(Packet10SimpleMessage.class);
		kryo.register(Packet11RequestChunk.class);
		kryo.register(Packet12SendChunk.class);
		kryo.register(Packet13PlayerJoined.class);
		kryo.register(Packet14PlayerLeft.class);
		kryo.register(Packet15Movment.class);
		kryo.register(Packet16Teleport.class);
		kryo.register(Packet17RequestAllPlayerIDs.class);
		kryo.register(Packet18AllPlayerIDs.class);
		kryo.register(Packet19RequestPlayerByID.class);
		kryo.register(Packet20ReturnPlayerByID.class);
		kryo.register(float[][].class);
		kryo.register(float[].class);
		kryo.register(int[][].class);
		kryo.register(int[].class);
	}
	public Client getClient(){
		return client;
	}

}


If you would Google these errors, you would actually find out much quicker what you are doing wrong. No offense, of course.

Check out the source code for the client class:

The constructor can optionally take in a buffer size. I would play around with it to see the size of the buffer you would need.

[quote]i have tried looking up this issue
[/quote]
and ok ill try that, thanks

Not really related to the question, but FYI, the server has “keep alive” functionality built in. All you have to do is increase the Client timeout to around 10 seconds or so (I forgot the exact time). You will see in the debug that the server sends a message every 7.5 seconds or so.

I used it for a short time but i found when there was a server or client crash Kryonet was unable to detect the connection loss itself so i had to make a packet to handle this

the answer is in the OP : you request a “chunk”, which sends TCP data, which is serialised, which is kaputt cos’ the buffer the serializer is writing is not big enough.

this means, either you serialize a message which is bigger than your serialization buffer, or the selector-write buffer is not big enough to store a message to send it actually.

a 3rd cause of error could be, even if the messages are small enough to fit into the write-buffer, your NIC could be unable to flush “fast enough”, so write-buffer stalls and explodes.

this is something kryonet is not handling well.

edit

a quick fix to that issue is probably simply smaller “chunks”, smaller messages.