top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Connection not closed at TCP level with websocket application

0 votes
776 views

We have a websocket application which keeps writing data to the clients.

We found that when tabs (not whole browser) of Firefox (ver. 22) is closed, the websocket connection is not closed. Anyway, reproducibility is very low. And the sendQ (netstat -an) keeps growing

So, what we did is. we kept sending heart beat from client. If this heart beat timeout occurs, we are trying to close the connection as follows

ByteBuffer bbuff = ByteBuffer.allocate(1);
bbuff.put((byte) 0);
messageInbound.getWsOutbound().close(0, bbuff);

Is this correct approach to close the connection from server? Because, the connection is not closed at lower level (netstat -an). Anyway, writing data to it , is stopped and sendQ stops growing.

# netstat -an | grep :8080
tcp 0 402376 172.22.59.176:8080 198.162.18.207:64805 ESTABLISHED
posted Aug 7, 2013 by Deepankar Dubey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
A ping from the server followed by a close if no pong is received within a set timeout should be fine.

1 Answer

+1 vote

You can try to close the connection from the client with something like:
document.addEventListener('beforeunload', function() {ws.close();})

answer Aug 7, 2013 by Mandeep Sehgal
Similar Questions
+1 vote

We have had issues with system resources, primarily RAM, maxing out and effectively overwhelming an Apache web server.
We have noticed that some of the default TCP time settings on Solaris 10 seem really high. Is there any sort of standard TCP settings that have been adopted, or suggested, for a Solaris 10 system running Apache 2.2?Can anyone share what they have done?

+1 vote

As per tomcat's performance tuning doc, 'tcpNoDelay' can be enabled/disabled at connector level.

Is there a programmatic way to set 'tcpNoDelay' to true for web socket connections ? I am using tomcat's proprietary web socket APIs in my application.

I have gone though the API documentation of tomcat's proprietary web socket implementation, I didn't see any API which allows application to override the 'tcpNoDelay' value.

As per doc for "writeTextMessage(CharBuffer msgCb)" of 'WsOutbound', for each write, tomcat flushes the socket buffer and sends the new frame with the buffer passed. Does that mean, flushing of socket buffer gives the same effect of disabling naggle's algorithm ?

+2 votes

What reasoning could be behind not using the TCP/SCTP for GTPv2 protocol ?

+2 votes

Is there a standard way to access ServletContext from a WebSocket ServerEndpoint ?

+2 votes

In our current generation web application we used session replication with tomcat clustering. (and a load balancer). That way, we received an auto fail-over when a client sends an ajax request to a tomcat node that failed.

In our next generation web application, We would like to have a similar behavior, only with web-sockets. So my questions are :

1) Is it possible ?
2) Does it involve websocket-session replication? if so, are there any guides on how to do that?

...