sending serialization file via sockets in java -
system.out.println("java awesome!");
pardon enthusiasm; can't believe how powerful java is, ability not save objects (and load them), main purpose, send them on network. must do, conducting beta-test. in beta-test, have given testers version of game saves data objects in location people don't know (we enlightened ones hahaha). work fine , dandy, except isn't meant long-term persistence. but, collect record.ser
, counter.bin
files (the latter tells me how many objects in record.ser
) via client/server interaction sockets (which know nothing about, until started reading it, still feel clueless). of examples have seen online (this 1 example: http://uisurumadushanka89.blogspot.com/2010/08/send-file-via-sockets-in-java.html ) sending file stream of bytes, namely objectoutputstream , objectinputstream. current version of game using save/load gamedata.
sorry long-winded intro, know have (steps-wise, can understand) send whole file. have reconstruct file byte-by-byte (or object-by-object)?
its pretty simple, actually. make objects serializable, , create objectoutputstream , objectinputstream connected whatever underlying stream have, fileinputstream, etc. write() whatever object want stream , read on other side.
heres example you.
for sockets
objectoutputstream objectout = new objectoutputstream(serversocket.getoutputstream()); objectinputstream objectin = new objectinputstream(clientsocket.getinputstream());
Comments
Post a Comment