Created
December 8, 2014 18:30
-
-
Save lpinca/6a8961c767960a4bf566 to your computer and use it in GitHub Desktop.
Faye WebSocket ECONNRESET
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
'use strict'; | |
var Faye = require('faye-websocket'); | |
var ws = new Faye.Client('ws://localhost:3000/'); | |
ws.on('open', function open() { | |
console.log('open'); | |
ws.send('Hello, world!'); | |
}); | |
ws.on('message', function message(event) { | |
console.log(event.data); | |
ws.close(); | |
process.exit(); | |
}); | |
ws.on('close', function close(event) { | |
console.log('close', event.code, event.reason); | |
ws = null; | |
}); |
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": "gh-321", | |
"version": "1.0.0", | |
"description": "", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"faye-websocket": "^0.8.1" | |
} | |
} |
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
'use strict'; | |
var Faye = require('faye-websocket') | |
, http = require('http'); | |
var server = http.createServer(); | |
server.on('upgrade', function upgrade(req, socket, head) { | |
if (!Faye.isWebSocket(req)) return socket.destroy(); | |
var ws = new Faye(req, socket, head); | |
ws.on('open', function open() { | |
ws.on('message', function echo(event) { | |
ws.send(event.data); | |
}); | |
ws.on('error', function error(err) { | |
console.error(err); | |
}); | |
ws.on('close', function close(event) { | |
console.log('close', event.code, event.reason); | |
ws = null; | |
}); | |
}); | |
}); | |
server.listen(3000, function listening() { | |
var bound = server.address(); | |
console.log('listening on %s:%s', bound.address, bound.port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment