0

I need to keep a connection to a server constantly. The thing is that I wont have wifi close to my IoT so it will need have attached a 3G module. What protocol is more efficient in terms of data consuming? REST or Sockets?

Alex Delgado
  • 984
  • 11
  • 19
  • Sockets will keep your connection always open and consume data connection, Its faster than REST. In REST you consume data only on demand. – Sasi Varunan Feb 10 '17 at 17:33
  • See [Websocket vs. REST](http://stackoverflow.com/questions/28613399/websocket-vs-rest-api-for-real-time-data/28618369#28618369) and [Ajax vs. Socket.io](http://stackoverflow.com/questions/30319618/ajax-vs-socket-io/30334848#30334848) for some related info. – jfriend00 Feb 14 '17 at 07:41

1 Answers1

0

I don't know what you mean by "sockets" - WebSocket? TCP sockets? But if you need to keep a connection to the server constantly then REST will not be able to do that. You are left with WebSocket, TCP sockets or you can fake the persistent connection with tricks like long-polling AJAX connections etc. In any case, TCP sockets will be least data consuming, WebSocket will not be much worse, and all HTTP-based methods will be the heaviest ones, especially those that require reconnecting like long-polling.

If you need a Node.js framework that lets you create APIs with WebSocket or TCP transport then you can take a look at ActionHero.js:

ActionHero is a multi-transport Node.JS API Server with integrated cluster capabilities and delayed tasks.

rsp
  • 107,747
  • 29
  • 201
  • 177