• Post Reply Bookmark Topic Watch Topic
  • New Topic

Knowing your streamed Objects

 
Sebastian Lindstaedt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

this is my first Post here, so please be nice ;-)

I have a Client-Server Application the Communicates on a socketbased Objecttransfer. So everything that travels between Server and Client has to be an Object (walks through an ObjectStream).
The Problem is that I also want to Transport Pictures from the Server to the Client(but I dont want to save them as a File in the Client, but hold them as an Object in the RAM). Therefore (on the Serverside) I use i.e. the PixelGrabber which gives me an Array that is streamable. But on the clientside I need to decide what kind of Object I get. That is, because through that stream I get "normal" Objects like "User", "Application", etc. and those Streamed Pictures, that I would like to read directly from the Stream with code like that:


But, as far as I understand, I cant make the decision about the Type of an object, before its completely transfered.
So, coming to the point (finally) Is there a way to forsee the type of an Object traveling an ObjectStream?

Sorry for writing sooooo much and thank you in advance for any hint, tip or pointer

Sebastian
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sebastian Lindstaedt:

this is my first Post here, so please be nice ;-)


Welcome to the JavaRanch. We pride ourselves on being friendly, so have no fear.
As for your question, in that kind of situation I like to make a Message interface that everything that will be transmitted will implement. The client or server, upon receiving a Message, invoke a process() method on it and the various message implementations take care of handling themselves, or informing a message bus that they have arrived. So your ImageMessage class would contain a byte array as well as the logic to convert it to a BufferedImage and inform the client or server that it has arrived and/or what to do with it.
 
Sebastian Lindstaedt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Joe Ess,

thank you for your post !
I managed the problem by using the pixelgrabber. This lets me put all the information of a rastered image file (like png, jpeg, etc.) into an int Array which I put myself into an Object and send it to the client. On the clientside I reconstruct an Image out of that Array and paint it on a JPanel :-)

So thank you again for the quick reply and I will surely ask more questions here :-)

Sebastian
[ November 09, 2006: Message edited by: Sebastian Lindstaedt ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!