giro
giro

Reputation: 431

How can I have my netty client detect if my netty server listens on a port (is available)?

I have a netty client that works fine if the server application is listening. But if the server application is not running and therefore not listening on the port, the client still runs as if it expects the server to be there.

I would like to handle the case when the server is not listening and in such a case not even send the data (and do something else instead, like telling the user to contact an admin or so). Is this even possible?

Note: If the client attempts to connect to an unspecified port or ip, my client throws exceptions which I can handle. My issue is that no exceptions are thrown when the server is not listening on the port it should normally listen to.

Upvotes: 0

Views: 1522

Answers (1)

Dmitriy Dumanskiy
Dmitriy Dumanskiy

Reputation: 12877

Yeap. Sometimes you can't detect that server is down/not listening on port anymore.

So for that case, you may add to your client pipeline ReadTimeoutHandler. Which will throw ReadTimeoutException in case your client didn't get any message from the server within the certain period of time. However, this may be not enough. For example, when your connection between server and client is not very active this exception could be thrown too. So for that case, you may need to implement ping-pong handlers, that will tell for your ReadTimeoutHandler that connection is active and it will not throw the exception in that case.

Upvotes: 2

Related Questions