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

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -