Skip to content

Instantly share code, notes, and snippets.

@lpinca
Last active August 29, 2015 14:11
Show Gist options
  • Save lpinca/bcde979a6d5eaebf1a2d to your computer and use it in GitHub Desktop.
Save lpinca/bcde979a6d5eaebf1a2d to your computer and use it in GitHub Desktop.
Engine.IO transport close when a polling data request is active
var Client = require('engine.io-client')
, Engine = require('engine.io')
, http = require('http');
var server = http.createServer()
, engine = new Engine();
engine.on('connection', function connection(socket) {
var onDataRequest = socket.transport.onDataRequest;
socket.transport.onDataRequest = function (req, res) {
onDataRequest.call(socket.transport, req, res);
socket.close();
};
socket.on('message', function (data) {
console.log(data);
});
});
server.on('request', function request(req, res) {
engine.handleRequest(req, res);
});
server.listen(function () {
var client = new Client('http://localhost:' + server.address().port, {
transports: [ 'polling' ]
});
client.on('open', function open() {
client.send('bar');
});
client.on('close', function close() {
server.close();
});
});
{
"name": "eio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"engine.io": "^1.4.3",
"engine.io-client": "^1.4.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment