Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
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 2668 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultrasnowfire

Senior Newbie


Projects: 1


YEA


« Posted 2012-07-29 10: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

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


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

arrays of what?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Ultrasnowfire

Senior Newbie


Projects: 1


YEA


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

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


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

arrays of integers, instances?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Damocles
« Reply #4 - Posted 2012-07-29 12: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
« Reply #5 - Posted 2012-07-29 15: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 unexpected features!
Offline Ultrasnowfire

Senior Newbie


Projects: 1


YEA


« Reply #6 - Posted 2012-07-29 21: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

Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Reply #7 - Posted 2012-07-30 03: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

Senior Member


Medals: 8



« Reply #8 - Posted 2012-08-01 12: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.

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (45 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (101 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!