Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
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  
  ReadableByteChannel & ObjectInputStream  (Read 1526 times)
0 Members and 1 Guest are viewing this topic.
Offline vrm

Junior Member




where I should sign ?


« Posted 2004-03-11 12:17:41 »

I'm trying to use a ReadableByteChannel and a  damn ObjectInputStream fropm serverside trying to read a serialized object (an array of object parameters) sent by a client
the client simply write the object to a socket :

ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
oss.write(new Param(arrayOfObjects)); // write my objects to the network

From the server side, I use selectors & keys, when I recieve my first read key, i'm
recieving a 4 bytes ByteBuffer !?, how nasty is this ObjectOutputStream ?

of course when I try to read the 4bytes with an ObjectInputStream I got an header exception

I start to think java  serialization & network aren't that friends, you know alternatives ?
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2004-03-12 20:32:58 »

Quote
I'm trying to use a ReadableByteChannel and a  damn ObjectInputStream fropm serverside trying to read a serialized object (an array of object parameters) sent by a client
the client simply write the object to a socket :

ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
oss.write(new Param(arrayOfObjects)); // write my objects to the network

From the server side, I use selectors & keys, when I recieve my first read key, i'm
recieving a 4 bytes ByteBuffer !?, how nasty is this ObjectOutputStream ?

of course when I try to read the 4bytes with an ObjectInputStream I got an header exception

I start to think java  serialization & network aren't that friends, you know alternatives ?



1. Are you sure the server isn't in non-blocking mode? That would explain why you received very little data in your first read...

2. WTF are you trying to do this? If you want to transfer objects, 99% of the time you're better off using RMI (and it's got a lot of useful features!). I know lots of people who are genuinely in the 1% situation (e.g. people who've needed more efficient implementations) but they tend to be pretty hard core situations. I'm not saying you definitely shouldn't be doing this, just that you *probably* shouldn't be Smiley.

3. There are numerous documented (by Sun,usually in the API docs, usually quite in-your-face) incompatibilities with serialization between different VM versions. Are your client and server both using EXACTLY the same JVM version? e.g. 1.4.2_04, not merely 1.4.2, nor 1.4.x

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2004-03-12 20:35:13 »

Quote

I start to think java  serialization & network aren't that friends, you know alternatives ?


1. RMI (it's part of java, look in the API docs)
2. Don't use serialization (it's overkill for many situations); either use a purpose-built network protocol (e.g. for games you normally need a UDP-based network protocol, not a high-level niche system like java's built-in serialization), or create a simple custom protocol of your own.

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vrm

Junior Member




where I should sign ?


« Reply #3 - Posted 2004-03-15 09:21:16 »

yes I'm in non-blocking mode and thats why  Grin

well got the same JVM on server & client side, but I'm going to kick serialization out, I just need it for big objects transfered 1 time like maps. I'm going to write my own externalization code for those, rest is mainly integer,strings and little basic types
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #4 - Posted 2004-03-15 09:43:25 »

Quote
yes I'm in non-blocking mode and thats why  Grin

well got the same JVM on server & client side, but I'm going to kick serialization out, I just need it for big objects transfered 1 time like maps. I'm going to write my own externalization code for those, rest is mainly integer,strings and little basic types


Make sure you add either an explicit "this object takes up the following N bytes in the stream" or an explicit "End-of-object" symbol in the stream. That way, with NIO, you just keep reading and checking whichever of those you chose until you've read in enough data that you KNOW you can deserialize the object (I mean "deserialize" in a general way, not specifically using JDK serialization).

malloc will be first against the wall when the revolution comes...
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.

radar3301 (12 views)
2014-09-21 23:33:17

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

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

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

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

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

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

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

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

Tekkerue (50 views)
2014-09-09 02:24:56
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!