networking - Java EOFException While Reading Object From A Server (not a file) -
this question exact duplicate of:
so, write object client so:
objectoutputstream out = new objectoutputstream(client.getoutputstream()); out.writeobject(args); out.close();
and receive object on client side so:
objectinputstream in = new objectinputstream(connection.getinputstream()); object objin; while(true) { if((objin = in.readobject()) != null) { //work obj } }
i never create output stream on client side or input stream on server side.
also, object send serializable.
thanks help!
edit: "duplicate" of question doesn't me answer problem, 1 not duplicate.
while(true) { if((objin = in.readobject()) != null) { //work obj } }
q. why testing null
? planning on sending null
? because that's time you'll ever one. a. because think readobject()
returns null
@ end of stream. although you've left out break
escape infinite loop.
it doesn't. throws eofexception.
loop should this:
try { while(true) { objin = in.readobject(); //work obj } } catch (eofexception exc) { // end of stream } { in.close(); }
Comments
Post a Comment