Last active
August 29, 2015 14:11
-
-
Save lpinca/bcde979a6d5eaebf1a2d to your computer and use it in GitHub Desktop.
Engine.IO transport close when a polling data request is active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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