Application Development

Tomcat implements the Java WebSocket 1.0 API defined by JSR-356.

 

There are several example applications that demonstrate how the WebSocket API can be used. You will need to look at both the client side HTML and the server side code.

Production usage

Although the WebSocket implementation does work with any of the HTTP connectors, it is not recommended to the WebSocket with the BIO HTTP connector as the typical uses of WebSocket (large numbers of mostly idle connections) is not a good fit for the HTTP BIO connector which requires that one thread is allocated per connection regardless of whether or not the connection is idle.

It has been reported (56304) that Linux can take large numbers of minutes to report dropped connections. When using WebSocket with the BIO HTTP connector this can result in threads blocking on writes for this period. This is likely to be undesirable. The time taken for the connection to be reported as dropped can be reduced by using the kernel network parameter /proc/sys/net/ipv4/tcp_retries2. Alternatively, one of the other HTTP connectors may be used as they utilise non-blocking IO enabling Tomcat to implement its own timeout mechanism to handle these cases.

Share this post
[social_warfare]
Overview of Websocket
Tomcat WebSocket specific configuration

Get industry recognized certification – Contact us

keyboard_arrow_up