Re: reading/writing myObject to a stream
babis85@gmail.com wrote:
Knute Johnson wrote:
babis85@gmail.com wrote:
Hello, i have a client/server application and i would like to be able
to write to the serverSocket an object of type myObject and then from
the case of the server i would like to read it.
How could I accomplish that. In C we can write() the sizeof(myObject)
and the read() the sizeof(myObject) and that's all.
Furthermore, i would like to write both objects of type myObject and
bytes. What Input/Output stream could i use for that purpose? Am i
asking very much, he he?
Thanks a lot for your help.
Two send objects around on streams they need to be Serializable and you
use ObjectInputStream/ObjectOutputStreams to read and write them. The
underlying stream can be from a file or socket connection. Take a look
at the docs and write some test programs. Post back here with your code
and problems.
--
Knute Johnson
email s/nospam/knute/
Thanks a lot my friend. That was exactly i was searching for.
But, i have one more question. In the doc of serializable
http://java.sun.com/j2se/1.4.2/docs/api/java/io/Serializable.html,
ObjectInput/OutputStream http://java.sun.com/j2se/1.4.2/docs/api/java/io/ObjectInputStream.html
and http://java.sun.com/j2se/1.4.2/docs/api/java/io/
ObjectOutputStream.html says sth about the reading/writing of objects
that have static members, but i didn't catch the point. Would there be
a problem for these objects?
Thanks again.
The docs appear to contradict themselves;
public final Object readObject()
throws IOException,
ClassNotFoundException
Read an object from the ObjectInputStream. The class of the object,
the signature of the class, and the values of the non-transient and
non-static fields of the class and all of its supertypes are read.
So I can't answer your question. I'm sure somebody will chime up here
though to give you an answer.
--
Knute Johnson
email s/nospam/knute/