R
R
Renat Iliev2015-01-31 18:36:09
Java
Renat Iliev, 2015-01-31 18:36:09

How to check if there is new data in ObjectInputStream?

There is a client-server connection. When a client connects, its connection is added to the list of connections and listening to the incoming stream begins, the socket.setKeepAlive(true) flag is also set, the same is done on the client (only one connection is listened to). When the server receives the object that the client passed to it (the exchange goes through the general Paket class), it sends it for processing, as a result, the answer may or may not arrive (depending on the data in the packet), the same is done by the client.
Now the essence of the request is how to determine when data appears in the ObjectInputStream (and?
Did this:
object_input_stream.available() > 0
I didn’t get the result.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Bykov, 2015-02-02
@jusio

There is no way to do this with standard streams. So there are two options: a separate thread that constantly reads from the ObjectInputStream and adds the results to a collection, or use java.nio.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question