I am writing a chat application in JavaServlets that uses long-polling to get chat notifications from the server. I have to persist the connection indefinitely without using something like WebSockets. I am using an AsyncListener to listen for the TimeOut event, if it occurs it sends a text string back to the client "Keep-Alive" and the client makes another request. And the process continues until the client is no longer receiving any messages.
Here is a portion of the code-snippet I am using-:
Now I am sure that there is a better way to keep the connection open, something a little more optimized. What would that be ? What are the considerations that need to be taken for bidirectional HTTP ?