I would like to send my gameworld (Mythruna block style) from my server to my client.
So I have a chunk containing a 1616128 array of bytes (containing the block-type) + 2 booleans + 2 integers that I would like to send in one message.
That should be 32778 bytes.
In the SocketConnector class from the jme there is the following declaration:
private byte buffer = new byte;
So I thought that sending 32778 bytes would be possible.
But I get every time a BufferOverflowException…
So I tried to find out where the map limit is that I can send in one message and I found that this is a 1616102 array. That would be approximately 26122 bytes. When I try to send a 1616103 (26378 bytes) array, I get the exception.
Now I have three questions:
Is the size limit of a message still 32kb like I read in an older thread?
If that is true, is there really about 6kb overhead in my message that I can’t localize?
Do I need to split the message into two messages, or is there another already implemented way to solve this (like compress the message)?
The limit is 32k. You can see that in MessageProtocol. I don’t remember what SocketConnector allocates 65536 but it’s one buffer per connector so it’s not to big of a deal.
If you are sending a 3D array, like bye then you are forgetting the data associated with each array entry. If you are sending byte then there are  byte arrays that could be any length or null. And 16 byte that could also be any length or null, and so on.
The array serializer tries to be as compact as possible but it wouldn’t surprise me if there is that much overhead in a 3D array of that size. If you flattened into a 1D array for transport then there would be less overhead. Run length encoding also helps.
Mythruna flattens, run length encodes, AND gzips the data. An most of my 32x32x32 “chunks” fit in a message… and I split them into two when they don’t.
i also try to send an object of 3 arrays (2x byte, 1x short all flatten). the max size is 97KB. i don’t know how to compress a message (gzip) and decompress. can you tell me a short code example? or how to split a message?
the constructor compresses it, getPayload() decompresses it. Do what you want with the serializable…
…and the fact that you called it a script (combined with what seems like a general lack of java knowledge) prompts me to ask how much java experience you have? You will struggle to get far with jme3 without learning java first (although once you do know java it works very well indeed).
how would you call it? code, class, snipped … script seems to be the same to me
my java skills are basic and i try to understand how to use your class. you have a constructor and one method for decompression… but if the message is compressed, how do i get the payload? because its private
the payload is a byte array but what should i do with it?
please give me a short example how to use your class with my message
this is the message class I use:
public class ChunkMessage extends AbstractMessage
private byte blocks;
private short lights;
private byte topLevelBlocks;
private int x;
private int z;
private Type type;
public ChunkMessage() // empty constructor required
public ChunkMessage(byte blocks, short lights, byte topLevelBlocks)
this.blocks = blocks;
this.lights = lights;
this.topLevelBlocks = topLevelBlocks;
type = Type.ResponseChunk;
public ChunkMessage(int x, int z)
this.x = x;
this.z = z;
type = Type.RequestChunk;
public byte getBlocks()
public short getLights()
public byte getTopLevelBlocks()
public int getX()
public int getZ()
public Type getType()
public enum Type
RequestChunk, ResponseChunk, RequestUpdate, ResponseUpdate, NotifyUpdate;
The class is really simple to use:
ChunkMessage cm = …blah;
CompressedMessage compressed = new CompressedMessage(cm);
// Send compressed
// at other end
CompressedMessage compressed = //however you read it
ChunkMessage cm = compressed.getPayload();
The protocol I was using these with I added some code at each end so when it received a message of type CompressedMessage it automatically retrieved the payload and then proceeded as though the payload is what had originally been received.
That way you could decide to compress or not compress whatever objects you like in order to send them and it was completely transparent on the other end.
It’s possible to use SpiderMonkey’s serializer to do compressed messages that are much more compact. But I already feel like the OP is in over their head. Networking a game is easily 100 times harder than compressing a message.
public class CompressedMessage implements Serializable // The annotation type Serializable should not be used as a superinterface for CompressedMessage
the implementation of an interface means that i have to implement all methods from the interface so i have some empty methods.
ChunkMessage cm = new ChunkMessage(…);
CompressedMessage compressed = new CompressedMessage(cm); // The constructor CompressedMessage(ChunkMessage) is undefined
source.send(compressed); // The method send(Message) in the type MessageConnection is not applicable for the arguments (CompressedMessage)
if i simply say:
it seems that nothing was sent to the client side
The problem is that there is no such thing as a “simple” networked game. That’s why we are saying start off single player - then once you understand that you can move up to networked.
You are probably importing the wrong Serializable or something. It’s just a marker interface, no methods implemented.
I don’t use the jME3 networking so can’t help you about sending the message. What you see is what you get - you need to take it from there…but if you are just starting out why are you trying to compress the message anyway? That’s an optimisation and premature optimisation makes for sad monkeys…