How to close connection forcedly in netty client side


How to close connection forcedly in netty client side



Here's the story,
I have a remote server and a client which behind a firewall. The client is implement by netty and it'll set up a keepalive connection to remote server. If there's no messages transfer in channel over 200 seconds, the firewall will reset the connection which is connect to remote server side, but the client side do not receive any tcp packets(such as RST package), so client consider that this connection is alive and the fact is not.
So how to close the unusual connection forcedly before the firewall handle this keepalive connection incorrectly?
BTW: I can't config the firewall




1 Answer
1



For tcp connections, you should send something to detect if it's active or broken. So I suggest you do something like these:



Let the client send a heartbeat packet regularly to keep the connection alive. By doing these, the firewall will keep the connection alive as you wish.



When the connection is broken , you can get a error immediately after sending the heartbeat packet. So you can close the channel or reconnect it again.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV