4

I need solution upstream much data every seconds. 200kBytes per seconds via wireless (WiFi) or Ethenet.

I selected MQTT, because It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

MQTT is better that Socket.io in network bandwidth usage? Or, MQTT is good solution for upload/publish realtime. MQTT can be used for charting system same as socket.io(WebSocket)?

1 Answers1

7

Socket.io does several things at once. This answer focuses on your note about the underlying protocol, WebSockets, though of course you could use those without Socket.io.

WebSockets vs. MQTT is an apples-to-baskets comparison, as each can work without the other or together. MQTT can work alone as an alternative to HTTP. WebSockets is an additional protocol on top of HTTP, and can keep a long-running connection open, so that a stream of messages can be sent over a long period without having to set up a new connection for each request. That connection can carry MQTT, or non-MQTT data like JSON objects, and has the benefit of providing a reliable two-way link whose messages arrive in order.

MQTT also has less overhead, for different reasons: it is designed with a publish-subscribe model (Pub-Sub Model) and optimizes for delivering data over narrow, slow, or unreliable connections. Though it omits many of the headers that accompany an HTTP message in favor of a few densely-coded bytes, the real difference is in speed of delivery. A top option for constrained embedded devices, though they are usually sending small messages and trying to conserve data/processing/power.

So they have different strengths, and can even be combined. MQTT-via-WebSockets is a common approach for using MQTT inside a webapp, though plain MQTT is the norm in lower-end devices (which may be hard-pressed to send that much data anyway). I suggest MQTT for sending from device to server, or WebSockets-MQTT for quickly receiving device data in the browser or ensuring the order of messages that are sent at high rates. An important exception would be for streaming - there have only been isolated reports of it over MQTT, while Socket.io reports it as a top feature. The balance will depend on what systems you have on both ends and what sort of charting is involved.

MBer
  • 2,218
  • 20
  • 34
  • Sure thing @DarrellSheley! Does it answer your question, or would you like any further explanation? – MBer Mar 16 '19 at 16:56
  • Thanks for your help. So, I cannot compare MQTT vs Socket in network bandwidth usage? –  Mar 23 '19 at 04:41
  • You can compare them if you define exactly what you want to send - such as "X messages of size Y over encrypted MQTT with authentication vs encrypted Socket.io". I do not have ready information on the results, and this answer mainly explains the technologies so you can pin down your requirements and come up with a test case. – MBer Mar 23 '19 at 05:46
  • What if I want to send messages which weighs maximum 5 kb over slow internet network (around 100kbps) and around 500-100 messages are concurrently fired. What would be the best way to implement a channel for this. Would socket.io + mqtt help in such kind of scenarios ? If yes is there a blog or some sort of online content on implementation of such kind of application ? – iniravpatel Dec 05 '19 at 08:07
  • @iniravpatel Based on your units, assuming that you mean 5 kilobits. MQTT is a perfectly good protocol for this. If you meant 1000 messages, then that would take up to 5kb*1000s/100kbps = 50s to get through though, so you might need to look at more compact transmissions - without compression, no protocol can make up for a lack of bandwidth. If you meant kilobytes, then that's 8 times worse and you seriously need to reassess the project. – MBer Dec 06 '19 at 00:05
  • 1
    "[WebSockets] can carry both HTTP and MQTT" - This is misleading. WebSockets run on top of HTTP. It would be bizarre to run HTTP on over websocket. Possible, sure, but I really struggle to imagine a reason why anybody would. Running MQTT over a websocket certainly does have its place. – Leopd Jul 08 '21 at 04:45
  • @Leopd Thanks, I meant that they can carry the same sort of data that would otherwise be sent in separate HTTP requests/responses. Updated. – MBer Jul 08 '21 at 19:02