Equivalent of BufferedReader.readNext() for ObjectInputStream in Java
I have a Server communicating with multiple clients through a socket connection. In my original program, messages were sent and recieved using a PrintWriter and a BufferedReader. When I checked to see if any new messages had been recei开发者_开发技巧ved, the BufferedReader would have them all stored and I could read them one by one.
I am now trying to do the same thing, but sending across objects rather than text with an ObjectOutputStream and an ObjectInputStream. However, when the the client or server receives more than one message before checking for new messages, it only processes one of them.
Is there a way that I can have a method similar to BufferedReader.readNext(), but for an ObjectInputStream? Is there a better way to send objects across? Or is there be a way to make a listener that responds each time a new message is received?
Thanks
There is ObjectInputStream#readObject() and you can also combine ObjectInputStream with a BufferedInputStream.
精彩评论