Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java serialization over network

Just want to know if there's a tutorial or a how-to for serializing objects, putting them into a stream over network, and deserialize it on the other side. I understand the principles of serialization, I/O, streams, sockets, and so on, I just would like an example of a client sending an object to a server to start with.

like image 330
sgy Avatar asked Apr 02 '09 01:04

sgy


2 Answers

This (pdf) is a useful tutorial which walks you through the basics of serialisation, and sockets, then ties the two concepts together (about halfway through the slides) to show how to serialise an object and send it from client to server (no RMI). I think that's precisely what you want.

like image 84
Brian Agnew Avatar answered Sep 25 '22 00:09

Brian Agnew


Its pretty simple, actually. Just make your objects serializable, and create an ObjectOutputStream and ObjectInputStream that are connected to whatever underlying stream you have, say FileInputStream, etc. Then just write() whatever object you want to the stream and read it on the other side.

Heres an example for you.

like image 44
John Ellinwood Avatar answered Sep 26 '22 00:09

John Ellinwood