开发者

Equivalent of BufferedReader.readNext() for ObjectInputStream in Java

开发者 https://www.devze.com 2023-01-19 09:38 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号