Search code examples
javawebsocketjava-websocket

java websocket api and old browsers


Java introduced Java API for WebSocket to implement WebSocket but all browsers don't support WebSockets properly.

Some browsers don't support it at all, the support in the other ones may be incompatible (non standard or incomplete).

  1. So why use Java API for WebSocket? Why was it introduced in the first place?
  2. How to deal with browser incompatibility and low support for WebSockets?
  3. Should we use Java API for WebSocket and do short polling for browsers that don't support WebSockets on the browser side?
  4. Isn't node.js with socket.io (which gives many additional facilities like re-connectivity, etc...) an obvious choice instead of Java API for WebSocket?

Solution

  • WebSockets has been created to enable server-to-client communication, it was impossible (or impractical) before that.

    To ease the transition (for both browser and servers), frameworks such as Atmosphere exist.

    They use a technique called "graceful degradation". It means that it will try to do the best (WebSockets), but if it is not available, it will fall down to "older" techniques such as Comet.

    That way you can design your application using WebSockets (which is good) still being compatible with old browsers.