I started using x-socket for writing a simple Comet client that can connect to a server implemented using grizzly comet with the goal of maintaining a persistent connection on which the server can push updates to the client. I wrote the following but I am not sure if this is the right way of doing it because I am not able to see any updates from the server. Can someone shed some light on this?
try {
String _GETRequest = "/sample/notify";
HttpClientConnection con = new HttpClientConnection("10.0.0.1", 5050);
con.setOption(HttpClientConnection.SO_KEEPALIVE, true);
con.setOption(HttpClientConnection.SO_TIMEOUT, 100000);
con.setConnectionTimeoutMillis(100000);
GetRequest request = new GetRequest(_GETRequest);
request.setParameter("id", id);
IHttpResponseHandler responseHandler = new ResponseHandler();
con.send(request, responseHandler);
org.xlightweb.client.HttpClient httpClient = new org.xlightweb.client.HttpClient();
request.setParameter("id", id);
con.send(request, responseHandler);
// Keep sending a request to keep the connection alive
//If I don't send anything, the server is terminating
//the connection with a FIN packet (oberved using wireshark)
//after 30 seconds even when I specified to keep the connection open
while(con.isOpen()) {
Thread.sleep(10000);
con.send(request, responseHandler);
};
} catch (ConnectException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}