Sending Map data to client

I am using Kryonet - to make a game multi-player. Created a server that handles player connections, position and also a list of entities (obstacles). The client uses LibGDX. This all works well, have tested it on EU and USA servers, I am in the UK, with around 5 connections.

The game has randomly generated tile maps which are stored as JSON, I zipped the file to decrease size its currently around 230kb. I tried to split this up into multiple smaller packets and send over TCP but get Buffer Overflow issues. Then tried to send over UDP but get packet loss.

So my questions are:

Should I be storing the map differently?
Should I be streaming the data differently?
Create a method to use UDP but guarantee delivery?
Split the map into small chunks and download them when needed?

Any advice is appreciated, failing to fix this I will go with a static map for the time being.

First thing.

Is the server generating a map and then sending this information to the client? If so what information? It should be purely data that the client can use to figure the rest out.

If the map is big, which I presume it is if a json file zipped still comes to 230kb. Does the client need all this data at once?

If the client does not need all this data at once, you should implement chunk loading. This way the client can request a part of the map that is required (say the spawn point on first join) then as the player moves the server can send the other chunks. It is up to the client to load and unload unnecessary chunks.

If the map is not utterly massive or even infinite, then the client has no reason to store this chunk data for more than 1 session. Just watch RAM usage, and know when it is time to start unloading chunks. After all it can always be requested from the server once again.

This is my 2 cents, I wrote this out of common sense/reading other posts. If I was to do it, it would be something like that.

Thanks for your advice, I will split the map up into sensible chunks. The only data the server sends is id, x, y, col, row, type.

The map is generated by the server on start up, so changes each time. While it wont be infinite it could be large.

I will implement chunks and see how it performs.


if you generate your map, the generation should be based on random numbers right ? In this case why not just send the initial seed used for the generation to all the clients for them to generate the same map on their side ? This way you’ll send only one long which is quite cheap :slight_smile:
If your generation is not based on a single seed maybe you could rework that :slight_smile:

I have been working on reducing the size of the stored map and now have it less than half the original size. also split it up into 81 chunks of 16x16 so sending it over the Internet should be less of an issue.

The idea of a seed would be much better though and I will try this out and see how it goes.

Thanks again for the help, I will share the output once its fully working and maybe a client so you can see what I am working on.

I implemented this last night, it will run differently in game of course but this is just proof of concept.


I used random seed generation in Procedra as someone proposed earlier.

When I changed from trying to send all the data, to just randomly generating a seed and sending the seed, ALL OF MY HEADACHES WENT AWAY.

It’s for sure the cheapest and easiest way.

It can look something like this:

	public long seed;
	public Random random;

        public Level(long seed){
        this.seed = seed;
    	 random = new Random(seed);


Just randomly generate a long, which can be the seed, to ensure no one will ever play the same map twice basically.

Then simply use the same random for every single thing you generate, and it’ll always generate the same map obviously :P.