Let’s assume I want to send many messages between 2 programs made in java that use TCP sockets.
I think the most convienient way is to send objects like:
PrintStream ps = new PrintStream(s.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(ps);
some_kind_of_object_here;
oos.writeObject(some_kind_of_object_here);
ps.print(oos);
I want to send, strings, numbers, HashMaps, boolean values
How can I do this using fx 1 object that can store all that properties?
I though about ArrayList that is serializable and we can put there everything but is not elegant way.
I want to send different types of data because user can choose from a variety of options that server can do for it.
Any advices?
Master, you know you can send any serializable object across a socket to another JVM, yes?
If so, the easiest way is to have a serializable object containing all your objects and then just forward that. A list of objects is probably the most simple. You can then deserialize it on the other side, and process the objects in the list in whatever way you need.
I would suggest you read up on the serialization technology in Java, so you know all the smart things you can do.
http://java.sun.com/javase/7/docs/technotes/guides/serialization/index.html