Skip to content

Instantly share code, notes, and snippets.

View lpinca's full-sized avatar

Luigi Pinca lpinca

  • Foligno (PG), Italy
View GitHub Profile
@lpinca
lpinca / README.md
Last active January 20, 2017 00:43
Primus `express-session` example

Upgrade requests should not save the session. If the session is saved when the WebSocket is closed, all the changes made by normal requests in the time span that goes from the opening of the WebSocket to the close of the same WebSocket are lost.

This is evident when this example page is refreshed in Chrome. For some odd reason the WebSocket request is closed after that the new request has been answered and the session is overriden by the old session that is retained in the old upgrade request.

@lpinca
lpinca / client.js
Created July 24, 2014 16:52
GH-268
var primus = new Primus({ strategy: false });
@lpinca
lpinca / client.js
Last active August 29, 2015 14:04
`primus-rooms` GH-44
var primus = new Primus({ strategy: false });
@lpinca
lpinca / client.js
Created September 22, 2014 14:22
Engine.IO data loss (҂⌣̀_⌣́)
var eio = require('engine.io-client');
var socket = new eio('http://localhost:3000/');
socket.on('open', function () {
setTimeout(function () {
socket.send('0');
}, 0);
});
socket.on('message', function (message) {
@lpinca
lpinca / einaros.js
Last active August 29, 2015 14:08
Faye WebSocket Y U NO EXIT (‡▼益▼)
var ws = require('ws')
, http = require('http');
var server = http.createServer();
var wss = new ws.Server({ noServer: true });
server.on('upgrade', function (req, socket, head) {
setTimeout(function () {
wss.handleUpgrade(req, socket, head, function (socket) {
socket.on('message', function (message) {
@lpinca
lpinca / index.js
Last active August 29, 2015 14:10
Close event not fired
'use strict';
var server = require('http').createServer();
var net = require('net');
function write(port, host) {
this.write([
'GET ws://' + host + ':' + port + '/ HTTP/1.1',
'Host: ' + host,
'Upgrade: websocket',
@lpinca
lpinca / client.js
Created December 7, 2014 14:08
permessage-deflate write after end
(function () {
var ws = new WebSocket('ws://localhost:3000');
ws.onopen = function () {
ws.send('shutdown');
};
})();
@lpinca
lpinca / package.json
Created December 8, 2014 09:03
Primus GH-321
{
"name": "gh-321",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
@lpinca
lpinca / client.js
Created December 8, 2014 18:30
Faye WebSocket ECONNRESET
'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!');
});
@lpinca
lpinca / client.js
Created December 14, 2014 10:58
Faye WebSocket ECONNRESET
(function () {
var ws = new WebSocket('ws://localhost:3000');
ws.onopen = function open() {
console.log('open');
ws.send('Hello, world!');
};
ws.onmessage = function message(event) {
console.log(event.data);