Note that there are some explanatory texts on larger screens.

plurals
  1. POFundamentals of iostream and read/writeObject calls
    text
    copied!<p>I am designing a java server to respond to multiple client requests. So the design basically has a server socket, accepts a client socket, creates a inputObjectStream and a outputObjectStream from the client input/outputStream.</p> <p>I then use writeobject on the client to make a request, readObject on the server to receive the request. Process it, write the object back on the same stream as a response, and on the client side readobject to process the response.</p> <p>Now, if I run the code on a android emulator/device works fine. The same piece of code if I run on a "android junit java test case", i get a exception after it processes all my requests. The exception is on the server side on readObject call.</p> <pre><code>java.io.EOFException at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2570) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1314) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)` </code></pre> <p>Question Is it a correct design to read/writeObjects on a iostream ?</p> <p><strong>Edited</strong></p> <p>I have the sample project uploaded on 4shared.com (http://www.4shared.com/archive/98gET_pV/Issue15426tar.html) OR (http://www.sendspace.com/file/v04zjp)</p> <p><strong>Test 1 (PASS)</strong></p> <ol> <li>TestServer project, run it as a Java Application</li> <li>TestClient project, run it as a Android Application</li> </ol> <p><strong>Console Output</strong></p> <p>Server Socket Opened /127.0.0.1</p> <p>Client Socket Accepted</p> <p>Input Stream created</p> <p>Output Stream created</p> <p>Read Object created</p> <p><strong>Test 2 (FAIL)</strong></p> <ol> <li>TestServer project, run it as a Java Application</li> <li>TestClient project, run it as a Android Junit Test</li> </ol> <p><strong>Console Output</strong></p> <p>Server Socket Opened /127.0.0.1</p> <p>Client Socket Accepted</p> <pre><code>Error : Unable to open server socket. Server wont load. java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2297) at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2766) at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:797) at java.io.ObjectInputStream.&lt;init&gt;(ObjectInputStream.java:297) at com.test.server.myThread.run(Main.java:52) at com.test.server.Main.main(Main.java:32) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload