Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sending 2D arrays over sockets  (Read 1730 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultrasnowfire

Senior Newbie


Projects: 1


YEA


« Posted 2012-07-29 12:05:14 »

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

Metallum on indieDB!!!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #1 - Posted 2012-07-29 12:23:39 »

arrays of what?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Ultrasnowfire

Senior Newbie


Projects: 1


YEA


« Reply #2 - Posted 2012-07-29 12:25:23 »

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

Metallum on indieDB!!!
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #3 - Posted 2012-07-29 13:12:50 »

arrays of integers, instances?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline Damocles
« Reply #4 - Posted 2012-07-29 14:25:52 »

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.

Offline zngga

Junior Member


Medals: 3


Current Project: Ascension (infinite RPG)


« Reply #5 - Posted 2012-07-29 17:39:11 »

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.

My code never has bugs... it just develops random features!
Offline Ultrasnowfire

Senior Newbie


Projects: 1


YEA


« Reply #6 - Posted 2012-07-29 23:22:55 »

arrays of integers, instances?

It uses my Block.class

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.

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

Thnx

Metallum on indieDB!!!
Offline JESTERRRRRR

Senior Member


Medals: 3



« Reply #7 - Posted 2012-07-30 05:45:26 »

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
Offline Phibedy

Junior Member


Medals: 2



« Reply #8 - Posted 2012-08-01 14:07:14 »

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:
http://www.java-gaming.org/topics/network-infrastructure/27051/msg/241326/view.html#msg241326
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
hobbles (6 views)
2013-05-22 00:54:55

cubemaster21 (74 views)
2013-05-17 21:29:12

alaslipknot (86 views)
2013-05-16 21:24:48

gouessej (115 views)
2013-05-16 00:53:38

gouessej (110 views)
2013-05-16 00:17:58

theagentd (121 views)
2013-05-15 15:01:13

theagentd (110 views)
2013-05-15 15:00:54

StreetDoggy (155 views)
2013-05-14 15:56:26

kutucuk (177 views)
2013-05-12 17:10:36

kutucuk (174 views)
2013-05-12 15:36:09
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.11 seconds with 21 queries.