i am creating a server-client application where the server sends a pdf file to the all connected clients. The problem is i get this error and i searched for a solution but c
BufferedReader
can buffer more data from the socket than you've read yet. So on the client side, the header of your byte[]
has probably already been read and buffered by your inFromServer
reader, and will not be available to your ObjectInputStream
.
Don't do that kind of thing. Either do all your marshaling "manually" (using the PrintWriter
/BufferedReader
pair), or do it all with object serialization with ObjectOutputStream
/ObjectInputStream
.