Java - Sending an object that points to a BufferedImage through a Socket -
me , group of friends working on project in java, , need regarding sending objects through sockets.
so far, have achieved send simple objects (ints, strings , whatnot) through sockets, using objectoutputstream
, objectinputstream
. however, ran huge problem today (huge us, anyway ^^)
we have tree structure, need send 1 pc another. problem that, within each node of tree, have reference bufferedimage , it's not serializable.
we have been researching lot today, , found out can use imageio.write()
send one bufferedimage through socket's outputstream, however, it's no since don't need send bufferedimage itself, whole tree located.
what need way (if exists) serialize each bufferedimage, converting class if necessary, while making tree, , having each node of tree reference new serializable class instead, tree can sent whole object...
we don't care performance, since trees we're sending aren't big (10-15 nodes top). in advance help, sorry lousy english. oh, , a... well, kind of homework, in case want keep in mind :-)
thanks!!
on each node can use writeobject() , readobject() check http://java.sun.com/developer/technicalarticles/programming/serialization/ more info
essentially become
public node implements serializable{ transient bufferedimage buff;//transient make won't written defaultwriteobject (which error) private void writeobject(objectoutputstream out)throws ioexception{ out.defaultwriteobject(); //write buff imageio out } private void readobject(objectinputstream in) throws ioexception, classnotfoundexception{ in.defaultreadobject(); //read buff imageio in } }
Comments
Post a Comment