Skip to content

Instantly share code, notes, and snippets.

View 3rd-Eden's full-sized avatar
💭
I have approximate knowledge of many things

Arnout Kazemier 3rd-Eden

💭
I have approximate knowledge of many things
View GitHub Profile
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<div id="output"></div>
<script>
function write (msg) {
var p = document.createElement('p');
p.innerHTML = 'LOG: ' + msg;

Client

LOG: *** <3 connecting
LOG: xhrpolling.get has been called
LOG: xhr statechange 4
LOG: got data 1::
LOG: got response for private: 1
LOG: url: http://10.0.1.5:8080/socket.io/1/xhr-polling/1721312700696629175
LOG: ------- got connect packet
<script src="/socket.io/socket.io.js"></script>
<script>
var chat = io.connect('/chat')
, news = io.connect('/news');
chat.on('connect', function () {
console.log('connect called on chat');
chat.emit('hi!');
@3rd-Eden
3rd-Eden / app.js
Created July 24, 2011 09:49
Socket.IO resource
/**
* Bootstrap app.
*/
require.paths.unshift(__dirname + '/../../lib/');
/**
* Module dependencies.
*/
// change this https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L469
if (this.roomClients[id]) {
for (var room in this.roomClients[id]) {
this.rooms[room].splice(this.rooms[room].indexOf(id), 1);
}
}
// to
@3rd-Eden
3rd-Eden / handshake.js
Created July 22, 2011 19:21
Handshake benchmark
var io = require('../').listen(8080)
, child = require('child_process');
io.sockets.on('connection', function () {
// nothing to do there as we are testing the handshake clean up.
});
// Check every 1 sec to see howmany ghost handshakes are allocated
var count = 0
, check = setInterval(function () {
npm ERR! TypeError: Object.keys called on non-object
npm ERR! at Function.keys (native)
npm ERR! at engineFilter (/usr/local/lib/node_modules/npm/lib/cache.js:281:10)
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:297:5
npm ERR! at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:67:7)
npm ERR! at cb (/usr/local/lib/node_modules/npm/lib/utils/graceful-fs.js:31:9)
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
@3rd-Eden
3rd-Eden / debugstatements.js
Created July 11, 2011 07:48
Debug statement
/**
* Manages connections to hosts.
*
* @param {String} uri
* @Param {Boolean} force creation of new socket (defaults to false)
* @api public
*/
io.connect = function (host, details) {
var uri = io.util.parseUri(host)
@3rd-Eden
3rd-Eden / debug.log
Created June 22, 2011 20:17
socket.io 0.7
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at Socket.<anonymous> (events.js:126:17)
at XHRPolling.setHandlers (/Users/V1/Sites/socket.io-node/lib/transport.js:137:15)
at XHRPolling.<anonymous> (/Users/V1/Sites/socket.io-node/lib/transport.js:94:10)
at XHRPolling.<anonymous> (/Users/V1/Sites/socket.io-node/lib/transports/http.js:82:39)
at XHRPolling.handleRequest (/Users/V1/Sites/socket.io-node/lib/transports/http-polling.js:61:41)
at XHRPolling.request (/Users/V1/Sites/socket.io-node/lib/transport.js:40:8)
at Manager.handleClient (/Users/V1/Sites/socket.io-node/lib/manager.js:323:21)
at Manager.handleHTTPRequest (/Users/V1/Sites/socket.io-node/lib/manager.js:295:8)
@3rd-Eden
3rd-Eden / factory.js
Created June 20, 2011 18:38
XHR request factory, only does the feature detection once and generates a dedicated function
util.request = (function(){
var fn = {
body: 'return null'
};
if ('XDomainRequest' in window){
fn.body = 'return new XDomainRequest();';
fn.xdomain = true;
} else if ('XMLHttpRequest' in window) {
fn.body = 'return new XMLHttpRequest();';