O'Reilly logo

Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON by Bhakti Mehta, Masoud Kalali

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Best practices for WebSockets based applications

This section will cover best practices for WebSockets based applications. The following topics will be covered:

  • Throttling the rate of sending data
  • Controlling the maximum size of the message
  • Working with proxy servers and WebSockets

Throttling the rate of sending data

After the WebSocket connection is opened, messages can be sent using the send function.

WebSockets have a bufferedAmount attribute that can be used to control the rate of sending data. Using the bufferedAmount attribute you can check the number of bytes that have been queued but not yet sent to the server.

Here is a snippet to test for the bufferedAmount attribute of WebSocket.

// This snippet checks for amount of data buffered but not sent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required