0

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?
superbob
  • 1,628
  • 13
  • 24
Masood Ahmad
  • 731
  • 4
  • 15
  • 38

1 Answers1

0

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.

superbob
  • 1,628
  • 13
  • 24
  • so java websockets api wont work all the time. That is the reason socket.io and node.js existed. (to deal with all gracefully degradation). my point 3 seems valid? – Masood Ahmad Jun 24 '14 at 07:32
  • @MasoodAhmad, your point 3 is valid in the sense that the server has to implement multiple transport (WebSocket + Long Pooling + Some other commet transport technique). The advantage of using a framework such as Atmosphere is that it can ease this multiple implementation. There are some [examples](https://github.com/Atmosphere/atmosphere-samples/blob/master/samples/jersey-pubsub/src/main/java/org/atmosphere/samples/pubsub/JerseyPubSub.java#L36) that illustrate that. Concretely you don't have to implement all (WebSockets, Long Pooling, ...) that by yourself. – superbob Jun 24 '14 at 07:58
  • One more thing (point 4), there are no obvious choice, you can do it in full Java or in full js (or pieces of both). Choose what seems to be better to you. Try and see the result. – superbob Jun 24 '14 at 08:01
  • so why do it with java socket api at all if we have to deal with things that node.js already deals with socket.io? – Masood Ahmad Jun 24 '14 at 09:17
  • It is more a matter of choosing what you **prefer** between Java (Java API for WabSocket and Atmosphere) or JavaScript (Node.js and Socket.IO). Both are able to handle WebSockets with graceful degradation. I have no absolute answer to this question. The best is to try and see what you find more suitable. – superbob Jun 24 '14 at 12:12