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 (404)
games submitted by our members
Games in WIP (289)
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  
  [KryoNet] Sending an int[][] over KryoNet  (Read 2290 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 3



« Posted 2012-08-19 23:03:52 »

Good evening.
I am trying to send a int[][] from server to client using Kryonet. The size of array is 256x256, but is the same if i use an 1x1 array.
The problem is that if i try to send the "Level" object, the connection stops (after x seconds, the client is disconnected, but server still thinks that he is still connected). I have tried using a byte[][] and a byte[], but nothing changes. The array values are between 0 and 6.

This is my Object:
1  
2  
3  
public static class Packet0Level {
   public int[][] map;
}

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Offline Danny02

JGO Knight


Medals: 36



« Reply #1 - Posted 2012-08-19 23:37:06 »

quite funny to use a serialization library to serialize a byte array into a byte array
Offline marcuiulian13

Senior Member


Medals: 3



« Reply #2 - Posted 2012-08-20 00:23:35 »

Okay, now i'm trying to send to the client data about every tile, using a for. The error i get is:

1  
2  
3  
4  
5  
6  
Exception in thread "pool-1-thread-1" java.lang.NullPointerException
   at com.minier.network.NetworkListener.received(NetworkListener.java:27)
   at com.esotericsoftware.kryonet.Listener$QueuedListener$3.run(Listener.java:102)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


And here is the code at line 27:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void received(Connection c, Object o) {
      if(o instanceof Packet0LevelInfo) {
         Packet0LevelInfo packet = (Packet0LevelInfo) o;
         Launcher.level = new Level(packet.levelWidth, packet.levelHeight);
      } else if(o instanceof Packet1LevelData) {
         Packet1LevelData packet = (Packet1LevelData) o;
/*LINE 27*/   Launcher.level.getMap()[packet.tileX][packet.tileY] = packet.tile; /*LINE 27*/
      } else if(o instanceof Packet2LevelFinished) {
         Launcher.levelLoaded = true;
      }
   }

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Wizard


Medals: 81
Projects: 3


Esoteric Software


« Reply #3 - Posted 2012-08-20 00:27:23 »

I don't see an int[][] in the code you posted.

Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



« Reply #4 - Posted 2012-08-20 00:35:03 »

so any of Launcher.level.getMap() is null. Set a breakpoint at that line to figure out which one.

I dont know if kryo have default support for arrays at the worst you have to write a custom Serializer.
 http://code.google.com/p/kryo/#KryoSerializable
probably you just need something like this:
1  
2  
...
kryo.register(int[].class);

Offline marcuiulian13

Senior Member


Medals: 3



« Reply #5 - Posted 2012-08-20 00:56:34 »

Already tried this...

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
Online matheus23

JGO Wizard


Medals: 71
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2012-08-22 10:03:00 »

I dont know if kryo have default support for arrays at the worst you have to write a custom Serializer.
This should drive Nate insane... maybe not...

Take a look at my development Blog: http://matheusdev.tumblr.com
Also look at my RPG Ruins of Revenge
Offline OttoMeier

Senior Member


Medals: 4
Projects: 1



« Reply #7 - Posted 2012-08-22 13:15:40 »

why?
Online matheus23

JGO Wizard


Medals: 71
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2012-08-22 20:44:57 »

quite funny to use a serialization library to serialize a byte array into a byte array

Take a look at my development Blog: http://matheusdev.tumblr.com
Also look at my RPG Ruins of Revenge
Offline marcuiulian13

Senior Member


Medals: 3



« Reply #9 - Posted 2012-08-26 00:37:58 »

Ok. Thank you. I already solved the problem.
The problem was that the array was too big for client so i broke it into smaller chunks that are sent one after other.  Grin

Check out my current project: http://cube3dev.blogspot.com/
Please comment/review/suggest.
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!
cubemaster21 (48 views)
2013-05-17 21:29:12

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

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

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

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

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

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

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

kutucuk (153 views)
2013-05-12 15:36:09

UnluckyDevil (163 views)
2013-05-12 05:09:57
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.106 seconds with 21 queries.