Skip to main content
GameDev.net gamedev.net
🔒 Locked

Java RMI: Printing remote object data to Client?

Started by Sean_Seanston Mar 31, 2011 at 7:23 PM 1 replies 1.3k views
Original Post
Sean_Seanston
Sean_Seanston
My situation is: I need to connect the Client to the Server and somehow print out information contained within an object inside a Remote Object to the Client. I don't need to manipulate it through the Client, just print it to the Client console.

How do I do that? You can't pass objects from Server to Client unless they're serializable and I can't think of any way to have the Server do something to solve this instead.
All I can think of is individual methods to painstakingly extract each piece of data in String form. So I put identification info in the method and get the Server to find the object and return the data in String form, but that seems ugly and tedious.

Implementing serializable seems like an awful pain, so is there any other way? Maybe I'm missing something obvious. I'm not used to RMI.
LorenzoGatti
LorenzoGatti
What's obvious is that they are your objects and your classes, so you should be able to
  • make them Serializable
  • get rid of non-Serializable fields you don't care for by marking them transient
  • serialize and deserialize an adequate alternate representation of needed non-Serializable fields with custom handlers.You don't need strings everywhere, and you don't need to be able to serialize any past, present and future Java object; just the closed world of your application.

    Java Serialization documentation
Omae Wa Mou Shindeiru
Sean_Seanston
Sean_Seanston
Well I've just gone with returning an array of Strings in the end.

Serialization seems to be the way to do it "properly", but this is part of a college assignment and I'm not sure, given the time and percentage, that such a seemingly complicated way of doing it is justifiable or particularly intended. Wasn't mentioned anywhere anyway which seems strange for such an essential part as it would be.

Thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.