Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2006

Tip: Looking for answers? Try searching our database.

Using ObjectInputStream/ObjectOutputStream

Thread view: 
pershing - 18 Aug 2006 14:02 GMT
I am trying to send objects across the network using
ObjectInputStream/ObjectOutputStream based on this example:

http://www.jguru.com/faq/view.jsp?EID=10472

I have created two separate projects: one for the client side and one
for the server side.

Both projects have their independent Message class (exact copy)
incorporated in the package of their respective project.

My problem is that I can send java defined objects such as a String
across the network using this example but when I try a custom object
like the Message class, on the receiving end I get a
ClassNotFoundException when I try to cast the input at this line

Message messageObject = (Message) in.readObject();

I have also tried some other home made classes with the same error. Is
this related to the fact that I place the Message class (and other home
made objects) in two separate packages depending on the project? The
client side project and the server side project would normaly be on
seperate machines so I can't have a common package which would be used
by both projects at the same time. Does anyone see how I can make this
example to work?

By he way, there is a mistake in that example where "123456789" should
be an 123456789

Thanks for any help
Gordon Beaton - 18 Aug 2006 14:17 GMT
> I get a ClassNotFoundException when I try to cast the input at this
> line
[quoted text clipped - 5 lines]
> other home made objects) in two separate packages depending on the
> project?

That will certainly be a problem, since client.Message is not the same
class as server.Message.

Instead of using two identical classes, why don't the client and
server share a single, common Message type?

Alternatively, use a custom mechanism for marshaling your messages,
one that isn't based on Serialization.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.