Questions tagged [engine.io]

Engine is the implementation of transport-based cross-browser/cross-device bi-directional communication layer for Socket.IO

GOAL

The main goal of Engine is ensuring the most reliable realtime communication. Unlike the previous Socket.IO core, it always establishes a long-polling connection first, then tries to upgrade to better transports that are "tested" on the side.

During the lifetime of the Socket.IO projects, we've found countless drawbacks to relying on HTML5 WebSocket or Flash Socket as the first connection mechanisms.

Both are clearly the right way of establishing a bidirectional communication, with HTML5 WebSocket being the way of the future. However, to answer most business needs, alternative traditional HTTP 1.1 mechanisms are just as good as delivering the same solution.

WebSocket/FlashSocket based connections have two fundamental benefits:

  1. Better server performance

    • A: Load balancers Load balancing a long polling connection poses a serious architectural nightmare since requests can come from any number of open sockets by the user agent, but they all need to be routed to the process and computer that owns the Engine connection. This negatively impacts RAM and CPU usage.

    • B: Network traffic WebSocket is designed around the premise that each message frame has to be surrounded by the least amount of data. In HTTP 1.1 transports, each message frame is surrounded by HTTP headers and chunked encoding frames. If you try to send the message "Hello world" with xhr-polling, the message ultimately becomes larger than if you were to send it with WebSocket.

    • C: Lightweight parser As an effect of B, the server has to do a lot more work to parse the network data and figure out the message when traditional HTTP requests are used (as in long polling). This means that another advantage of WebSocket is less server CPU usage. Better user experience.

Due to the reasons stated in point 1, the most important effect of being able to establish a WebSocket connection is raw data transfer speed, which translates in some cases in better user experience.

Applications with heavy realtime interaction (such as games) will benefit greatly, whereas applications like realtime chat (Gmail/Facebook), newsfeeds (Facebook) or timelines (Twitter) will have negligible user experience improvements.

Having said this, attempting to establish a WebSocket connection directly so far has proven problematic:

  1. Proxies Many corporate proxies block WebSocket traffic.

  2. Personal firewall and antivirus software As a result of our research, we've found that at least 3 personal security applications block WebSocket traffic.

  3. Cloud application platforms Platforms like Heroku or No.de have had trouble keeping up with the fast-paced nature of the evolution of the WebSocket protocol. Applications therefore end up inevitably using long polling, but the seamless installation experience of Socket.IO we strive for ("require() it and it just works") disappears.

Some of these problems have solutions. In the case of proxies and personal programs, however, the solutions many times involve upgrading software. Experience has shown that relying on client software upgrades to deliver a business solution is fruitless: the very existence of this project has to do with a fragmented panorama of user agent distribution, with clients connecting with latest versions of the most modern user agents (Chrome, Firefox and Safari), but others with versions as low as IE 5.5.

From the user perspective, an unsuccessful WebSocket connection can translate in up to at least 10 seconds of waiting for the realtime application to begin exchanging data. This perceptively hurts user experience.

To summarize, Engine focuses on reliability and user experience first, marginal potential UX improvements and increased server performance second. Engine is the result of all the lessons learned with WebSocket in the wild.

Architecture

The main premise of Engine, and the core of its existence, is the ability to swap transports on the fly. A connection starts as xhr-polling, but it can switch to WebSocket.

The central problem this poses is: how do we switch transports without losing messages?

Engine only switches from polling to another transport in between polling cycles. Since the server closes the connection after a certain timeout when there's no activity, and the polling transport implementation buffers messages in between connections, this ensures no message loss and optimal performance.

Another benefit of this design is that we workaround almost all the limitations of Flash Socket, such as slow connection times, increased file size (we can safely lazy load it without hurting user experience), etc.

FAQ

  • Can I use engine without Socket.IO ?

Absolutely. Although the recommended framework for building realtime applications is Socket.IO, since it provides fundamental features for real-world applications such as multiplexing, reconnection support, etc.

Engine is to Socket.IO what Connect is to Express. An essential piece for building realtime frameworks, but something you probably won't be using for building actual applications.

  • Does the server serve the client?

No. The main reason is that Engine is meant to be bundled with frameworks. Socket.IO includes Engine, therefore serving two clients is not necessary. If you use Socket.IO, including <script src="/socket.io/socket.io.js"> has you covered.

  • Can I implement Engine in other languages?

Absolutely. The SPEC file contains the most up to date description of the implementation specification at all times. If you're targeting the latest stable release of Engine, make sure to look at the file in the appropriate git branch/tag.

The Java/NIO implementation will be officially supported, and is being worked on by the author.

52 questions
452
votes
3 answers

Which websocket library to use with Node.js?

Currently there is a plethora of websocket libraries for node.js, the most popular seem to…
balupton
  • 47,113
  • 32
  • 131
  • 182
64
votes
4 answers

What's the difference between engine.io and socket.io?

Regarding node.js, I'm using socket.io for real-time socket connection from the client application to the server application. I just heard about engine.io. Is engine.io a replacement for socket.io? I could not find any useful information on…
L N
  • 2,856
  • 4
  • 20
  • 30
35
votes
3 answers

Engine.io or SockJS, which one to choose?

I have run into trouble with Socket.io regarding memory leaks and scaling issues lately. My decision to use Socket.io was made over a year ago when it was undoubtedly the best library to use. Now that Socket.io causes much trouble, I spent time…
1nsane
  • 1,017
  • 2
  • 12
  • 21
9
votes
1 answer

Which node.js socket engine should I use?

I'm at the start of a project to build a real time chat application spanning accross a website and an Android app. Since I want to prevent continuous polling on all sorts of API calls, I want to use websockets (which I have no experience with) and…
kramer65
  • 50,427
  • 120
  • 308
  • 488
6
votes
2 answers

Socket.io "Invalid frame header" error with independent websocket server

Is there a way to have a separate websocket server work alongside socket.io on a different path? let http = require('http'); let express = require('express'); let socketio = require('socket.io'); let websocket = require('ws'); let httpServer =…
5
votes
3 answers

socket.io - how to access unhandled messages?

How can you detect that you received a message on a socket.io connection that you do not have a handler for? example: // client socket.emit('test', 'message'); // server io.on('connection', function (socket) { console.log('connection…
pe-sean
  • 51
  • 1
4
votes
0 answers

Node.js - Compressing data on server, sending it via Engine.IO Web Sockets, and decompressing it on client

I GZip some JSON data on server, send it via Engine.IO implementation of Web Sockets function sendResourceDataToObserver(socket, data) { zlib.gzip(data, function (_, result) { socket.send(result); }); } and decompress it with ZLIB module…
Deniz Ozger
  • 2,565
  • 23
  • 27
4
votes
1 answer

Engine.IO tutorial needed

Hi I am trying to use Engine.IO. As stated here on StackOverflow it is supposed to be low level version of Socket.IO. Also it supposed to be better and newer. Also it should give me the ability to easily exchange messages between browser client and…
exebook
  • 32,014
  • 33
  • 141
  • 226
3
votes
1 answer

In Socket.IO, what is the "io" cookie used for?

I know it is a session cookie, but for which purpose does Socket.IO actually use the io cookie? I know I can disable it, but couldn't find anything else on the docs. Why is it enabled by default and what I'm going to lose or break if I disable it?
cprcrack
  • 17,118
  • 7
  • 88
  • 91
3
votes
1 answer

Send JSON and blob together

I'm writing a simple streaming service. A browser An open a web socket to a server, then another browser B open a new socket to the same server. Browser A register a video by its camera (MediaRecorder API) and send it to the server. The server…
wiulma
  • 101
  • 1
  • 1
  • 4
3
votes
1 answer

Node.js + Socket.io | Set custom headers on the server

I use Helmet with Express to set quite some security HTTP headers from the server side. This is nicely done, when rendering client pages on top of the node.js app, using: var app = express(); app.use(helmet()); .. res.render("pages/index",…
flaesh
  • 262
  • 5
  • 17
3
votes
1 answer

What is the relationship between ws engine.io and socket.io

This question basically makes it sound like the node library Socket.io uses the library engine.io which uses ws. What role do each of these play given that each one can independantly create a WebSocket connection?
Startec
  • 12,496
  • 23
  • 93
  • 160
3
votes
0 answers

Socket.io / Node.js: "value is out of bounds" on socket connection from client

I am working on getting nodejs / socket.io / express running on busybox linux on an ARMv5TE processor. I have nodejs up and running and the following code runs without errors. var app = require('express')(); var server =…
AnalogWeapon
  • 550
  • 1
  • 4
  • 16
2
votes
1 answer

Is there a way of making socket.io client version 3.0 make use of EIO=3 in javascript

The goal is to connect to a socket.io server which uses version 3 of Engine.IO transport protocol EIO=3... This kind of 2 questions in one due to uncertainty... The first is can socket.io client version 3.0 make use of EIO=3 instead of using EIO=4…
Exboy
  • 79
  • 7
2
votes
1 answer

Does socket.io upgrade transport to websocket from polling ?

I am using nodejs with socket.io and express frame work. Following is the log output I get, when I run command DEBUG=* /bin/www Following is the log output. engine intercepting request for path "/socket.io/" +2m engine handling "GET" http…
Venkat Kotra
  • 10,413
  • 3
  • 49
  • 53
1
2 3 4