WojtusJ
WojtusJ

Reputation: 1318

Getting "java.io.EOFException" after sending a file throught socket

I'm trying to implement basic communication through sockets, what I have now is:

Unfortunately, that last step on client side fails with exception:

    java.io.EOFException
        at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
        at java.io.ObjectInputStream.readObject0(Unknown Source)
        at java.io.ObjectInputStream.readObject(Unknown Source)
        at basketAnalysis.client.Client.run(Client.java:74)
        at java.lang.Thread.run(Unknown Source)

I want client to block on waiting for server response after sending the file, but it suddenly finishes with the exception after sending the file. I am pretty sure that I do something wrong with switching between simple streams and Object streams.

Does anybody know what should I change to haave it working?

Thank you in advance!

Upvotes: 1

Views: 4847

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499860

I think your basic misunderstanding is here:

clients wants to send a file so opens different output stream

OutputStream os = clientSocket_.getOutputStream();

That doesn't open a different output stream - that will get another reference to the same output stream which you've already got wrapped in the ObjectOutputStream. If you want two streams of data, you'll need to open two separate connections.

Upvotes: 3

Related Questions