Sending 2D arrays over sockets

Hey,

I have been makin a 2D mining game called Metallum (check it out: http://www.java-gaming.org/topics/wip-metallum-miner-2d-mining-game/26980/view.html) and ive been trying to make it an online game. My main problem with it is I don’t know how to send 2D arrays over sockets, once I have this it will make it easier for me to make it an online game.

Thnx,
Ultra

arrays of what?

The array stores the block data of the world like at 1,1 it will be air or 30,30 stone

arrays of integers, instances?

there are many possible routes.

Before sending it, try to create a byte[] out if your int[][] blockdata array.

Sending this Byte Array you can just use your normal DataOutputStream

But sending a large 2D blocklevel will create a lot of traffic.
You should somehow compress the data before sendig it.

Use Kryonet instead: http://code.google.com/p/kryonet/

It is what I am using for my game, and I am able to send very large arrays of complex data with ease!

I know this doesn’t really answer your question, except to give you an alternative way of doing things, but I thought I would recommend it anyway.

It uses my Block.class

When I get on my PC I will have a good look at this (looks easier than the way I use)

Thnx

LMAO that donut man is sick, I love him

edit: just noticed this post ended up here… I must of been having an attack of some sort

If you wanna do it on your own, you should create an object out of it. It´s easyer to handle afterwards.
After that you serialize it, then you split it in smaller byte[] (if it´s bigger then 64 kb).
You add some bytes to each packet, I prefere
byte[0] = is splited?
byte[1] + byte[2] = sendNumber (just for controlling, it increases after every sent object)
byte[3] = how many parts your object has
byte[4] = what part is it
…What you need else.
Afterwards you can easily put the parts together and if some parts are lost, you can order them from the server again.
best regs. phib

EDIT: Got a better solution: