3

I’m developing the back-end of a real-time Java application, using Hibernate for data modeling, where I want to offer an API to feed the client side, that could be a webpage, mobile app or even a desktop application. The server is updated by RTU’s once in a while, maybe just one or two updates every few minutes, but I want the server to inform the clients with every change produced in real time. So I have made some research about websockets, and it seems to be some controversy about its use. As my application won’t have a big amount of non-requested traffic from server to client, I don’t know if the use of websockets is the best solution. But on the other hand, if I use REST services, I will need some workaround to ensure that clients receive every change produced in server. In this case, what issues could I face developing this application with websockets? Are they the best approach?

Edit: The difference between the websocket vs rest API for real time data? post and mine it's the rate of unrequested traffic from server to client is going to be quite least, because there may pass several minutes between two server updates. As far as I know, websockets are a good choice for applications that need constant updating from server, as online games, but in my case I don't know if the cons of using it would overweigh the pros. This article made me doubt about the suitability of using websockets on my application

Community
  • 1
  • 1
Juan
  • 1,680
  • 1
  • 14
  • 21
  • Also likely a duplicate of [Ajax vs Socket.io](http://stackoverflow.com/questions/30319618/ajax-vs-socket-io/30334848#30334848) – jfriend00 Feb 23 '17 at 23:33

1 Answers1

7

There is no one correct answer, but a few points to consider:

  • WebSocket is a mature technology by now, with support in all modern browsers and libraries for any programming language.
  • With WebSocket you get a persistent connection which allows you to send updates immediately - which is precisely what you want to do. With a REST API you need some workaround (such as long-polling) - so the technology, while it can be done, is not a good match for your use case.
gzost
  • 2,299
  • 1
  • 17
  • 25