Java serialization over the network

I just want to know if there is a manual or instructions for serializing objects, placing them in a stream over the network, and deserializing it on the other hand. I understand the principles of serialization, I / O, threads, sockets, etc. I just would like the client sending the object to the server to start with it.

+7
java serialization network-programming
source share
4 answers

This (pdf) is a useful tutorial in which you understand the basics of serialization and sockets, and then combine the two concepts (about halfway through the slides) to show how to serialize the object and send it from the client to the server (without RMI). I think that is exactly what you want.

+9
source share

This is actually quite simple. Just make your objects serializable and create an ObjectOutputStream and ObjectInputStream that are connected to any underlying stream you have, say FileInputStream, etc. Then just write () any object you want to pass, and read it from the other side.

Here is one for you.

+7
source share

Java provides (binary) serialization of objects using ObjectOutputStream (and ObjectInputStream ). You can simply writeObject () to the stream and readObject () at the other end. All you have to do for this is to implement the Serializable interface.

But instead of doing it manually, you may be interested in taking it one level and using the Remote Method Invocation . With RMI, you can call methods on objects that live in another JVM, and all serialization and networking takes place under the hood.

And for completeness, XML bean serialization also exists if you cannot use the binary format. This XML format is very general (read: verbose and ugly), but there are some popular libraries (such as XStream ) that create alternative XML serializations.

+5
source share

you can create streams of objects using java api and send any serializable object. but you must remember that they are not encrypted over the network:

on the sender side:

CustomObject objectToSend=new CustomObject(); Socket s = new Socket("yourhostname", 1234); ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream()); out.writeObject(objectToSend); out.flush(); 

and on the receiving side:

 ServerSocket server = new ServerSocket(1234); Socket s = server.accept(); ObjectInputStream in = new ObjectInputStream(s.getInputStream()); CustomObject objectReceived = (CustomObject) in.readObject(); 
+2
source share

All Articles