Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 Object through TCP/IP...  (Read 6898 times)
0 Members and 1 Guest are viewing this topic.
Offline LordWilson

Junior Newbie

Who runs it???...TKE Runs it...

« Posted 2003-04-23 20:40:08 »

I am trying to send a Deck object that I have created by subclassing the Vector class through a TCP/IP Connection...I'm not sure if i'm doing this correctly, however...the problem isn't getting the deck SENT, i don't think, but receiving it correctly is the problem...

The Client side code is as follows...

InetAddress server = InetAddress.getByName("hippo");
                 int port = 22222;
                 Socket socket = new Socket(server, port);
                 System.out.println("Connected to server...attempting to send deck");
                 ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());

(I'm catching everything necessary...)

Please don't poke too much fun at the code, i'm just beginning this TCP/IP stuff ;-)

anyways, i'm sure that the message is getting to the server...because the connection is made fine...

server code is as follows...

int servPort = 22222;
             ServerSocket serverSocket = new ServerSocket(servPort);
                   Socket inSocket = serverSocket.accept();
                   ObjectInputStream ois = new ObjectInputStream(inSocket.getInputStream());
                   Object possibleDeck = ois.readObject();
                       System.out.println("Checking for Instance");
                       if(possibleDeck instanceof Deck){
                             System.out.println("It's a Deck");
                             deck = (Deck)possibleDeck;                        
                             System.out.println("Deck Loaded..."      );
                             System.out.println("It's not a deck");

it gives the error message (which i will display in a sec) when it reaches the line:  "Object possibleDeck = ois.readObject();"

The error message is as follows... javax.swing.JComponent; local class incompatible:
stream classdesc serialVersionUID = 4775608949283930591, local class serialVers
ionUID = -7908749299918704233

I can't seem to fix might help to know if where the problem is it the WAY that i'm sending the object (basically, CAN I DO IT THAT WAY????)...or does it have to do with something else?...

any help is appreciated...even suggestions on how to fix it (sample code is *always* welcome...) ...

if i'm not sending the object in the correct manner, what is the best (easiest, even) to send one object from one machine to another?...

Thanx for any help....


Don't talk...You'll seem less stupid that way...
Offline mill

Junior Devvie

popcorn freak

« Reply #1 - Posted 2003-04-24 12:17:09 »

Vector itselt is serializable, but you may have objects in your Deck that are not or perhaps you have attributes which aren't.

try making your attributes transient and see if that works.

if objects aren't serializable i think you get another error message than the one you get (if i remember correctly)

anyway, from the error message it looks like the object sent is not the same kind as the one that's received.

you are using the same class file, right? as in you haven't recompiled the client's Deck-file or something?

Offline LordWilson

Junior Newbie

Who runs it???...TKE Runs it...

« Reply #2 - Posted 2003-04-25 02:36:30 »

I am using the same classes...

I think i might be able to narrow it down, however...

it says the exception is coming from javax.swing.Jcomponent...a Deck object is basically a subclass of a Vector (perfectly serializable, btw)...the Deck contains any number of Card objects...Cards are basically just subclasses of a, a JButton is a JComponent, so I'm pretty sure that the problem lies within that class...however, I'm not sure how serialization works with hierarchy...

in order to make the classes compatible, i have set the serialVersionUID in both the Deck class and the Card class...

static final long serialVersionUID = -8436333800348538015L;

static final long serialVersionUID = -8293881053128968132L;

as you can see, those SVUIDs aren't either of the ones described in the exception...

does anyone have a clue as to what I should do to fix this problem???...has anyone run into this before?...

Thanx for any input...


Don't talk...You'll seem less stupid that way...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Devvie

Medals: 1

Who, me?

« Reply #3 - Posted 2003-04-25 10:04:16 »

What are the JVMs at either end of the connection?

Hellomynameis Charlie Dobbie.
Offline coilcore

Senior Newbie

Java games rock!

« Reply #4 - Posted 2003-04-25 19:34:13 »

When you serialize an object every member within that object is also serailized, and each of any members objects are serialized, and so on.  The way to prevent this is to mark a member as 'transient' this means it will not be serialized and therefore will not be in your data you send across the wire.  e.g.

 public ArrayList a = new ArrayList();
 public transient ArrayList b = new ArrayList();

The deserialized object ArrayList a will have all the contents from the original object, but b will be empty even if the serialized class had data there.

Clearly you are trying to deserialize something thats not the same between each JVM (either by your own classes or JVM version).  I'd suggest starting near the top and narrowing as you go making objects transient to try to isolate the problem.  

Offline blahblahblahh

JGO Coder

Medals: 1

« Reply #5 - Posted 2003-04-26 20:11:32 »


The error message is as follows... javax.swing.JComponent; local class incompatible:

In general, NONE of the gui classes are serializable. Many AWT classes are inherently non-serializable (I've heard before that this is because, under the hood, they contain references to things like your local graphics memory; Sun could still have created a workaround, but apparently haven't). Nearly all Swing classes have for a while come with the comment (written in the docs for every class - have you READ the docs for the classes you are using?) "blah blah this is NOT serializable between different VM versions and/or platforms...this will be fixed in a later version of  swing blah blah etc".

In general, just never try to serialize a Swing class. Although I do feel your pain - sometimes (though I very much doubt this is the case for you) you have to serialize gui classes. However, why on earth do you want to send a Button over the network? Just obey the M/V/C architecture (simple concept: separate your data (Model), display (View) and mouse-handling etc (Controller) - M,V,C. Read the Swing docs for info) and make a Model class representing the underlying data of your cards, and send that.

Have it DISPLAYED both ends by a separate class (a View, from the M/V/C terminology).

If this isn't clear, let me know and I'll try again; been awake almost 20 hours, and I'm not thinking too straight Smiley.

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

Junior Newbie

Who runs it???...TKE Runs it...

« Reply #6 - Posted 2003-04-26 23:18:53 », I've managed to get the Deck successfully deserialized...that's the good news...

the bad that I had to be using the same version of the JVM on both sides (precisely as all of you had implied)...and that's not taking advantage of the platform independency that java is used for...SO...I will be taking the advice of mr. blahblahblahh and using the M/V/C technique...

I guess i had to learn the lesson of swing serialization the hard way...

thanx for helping me out, fellas...I appreciate it...


Don't talk...You'll seem less stupid that way...
Pages: [1]
  ignore  |  Print  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (74 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!