Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using dgram (UDP) with Socket.IO at what speed are the datagrams sent? (node)

I am using socket.io and the dgram node library to send UDP messages from one program to a browser via node.
The code looks just like the socket.io example

var dgram = require("dgram");
var dServer = dgram.createSocket("udp4");
dServer.bind(12345, '0.0.0.0');
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
  dServer.on("message", function (msg) {
     socket.send('message', msg);
  });
});

My question is at what speed are the datagrams ultimately being sent to the browser? Are they being sent at TCP speeds, web socket speeds (which I understand to be slower) or UDP speeds (which I understand are quicker when it comes to real time communication).

Also, in this example is io perpetually listening on port 80 (meaning it can only receive things at http / tcp speeds) or does it just listen to establish the socket connection and then can stop listening (and let the socket connection take over)

like image 475
Startec Avatar asked Mar 26 '14 01:03

Startec


1 Answers

The speed of UDP, TCP and WebSockets "Packets" are the same (e.g. wire speed), but they differ in overhead and reliability.

  • WebSockets are a tunnel within an existing HTTP connection, so in effect TCP with more overhead. But they use existing ways in tunneling through NAT router and firewalls.
  • TCP has reliability guarantees, e.g. no packets get lost and no duplicates. TCP needs an initial 3-way handshake, but this is once for a connection and not for each data chunk.
  • UDP is fire and forget and you need to implement you own reliability on top if you need it. Apart from that, I'm not sure if the browser will even natively accept your UDP packet, at least outside RTP context (e.g. WebRTC). It might work with Java and Flash.
like image 92
Steffen Ullrich Avatar answered Oct 21 '22 18:10

Steffen Ullrich