server-plugin/plugin.js
function failFirstRequest(server) {
    var listeners = server.listeners("request"),
        existingListeners = [];
    for (var i = 0, l = listeners.length; i < l; i++) {
        existingListeners[i] = listeners[i];
    }
    server.removeAllListeners("request");
    server.on("request", function (req, res) {
        var fireExisting = true;
        if (/^\/transport\/server\//.test(req.url)) {
            fireExisting = onTransportRequest(req, res);
        }
        if (fireExisting) {
            for (var i = 0, l = existingListeners.length; i < l; i++) {
                existingListeners[i].call(server, req, res);
            }
        }
    });

    var count = 0;
    function onTransportRequest(req, res) {
        count += 1;
        console.log("REQUEST", req.url, count);
        if (count === 1) {
            console.log("  Fail request");
            res.end("<An unparsable response>");
            return false;
        }
        return true;
    }
}
function failFirstRequest(server) {
    var listeners = server.listeners("request"),
        existingListeners = [];
    for (var i = 0, l = listeners.length; i < l; i++) {
        existingListeners[i] = listeners[i];
    }
    server.removeAllListeners("request");
    server.on("request", function (req, res) {
        var fireExisting = true;
        if (/^\/transport\/server\//.test(req.url)) {
            fireExisting = onTransportRequest(req, res);
        }
        if (fireExisting) {
            for (var i = 0, l = existingListeners.length; i < l; i++) {
                existingListeners[i].call(server, req, res);
            }
        }
    });

    var count = 0;
    function onTransportRequest(req, res) {
        count += 1;
        console.log("REQUEST", req.url, count);
        if (count === 1) {
            console.log("  Fail request");
            res.end("<An unparsable response>");
            return false;
        }
        return true;
    }
}
function failFirstRequest ( server ) { var listeners = server . listeners ( "request" ) , existingListeners = [ ] ; for ( var i = 0 , l = listeners . length ; i < l ; i ++ ) { existingListeners [ i ] = listeners [ i ] ; } server . removeAllListeners ( "request" ) ; server . on ( "request" , function ( req , res ) { var fireExisting = true ; if ( / ^\/transport\/server\/ / . test ( req . url ) ) { fireExisting = onTransportRequest ( req , res ) ; } if ( fireExisting ) { for ( var i = 0 , l = existingListeners . length ; i < l ; i ++ ) { existingListeners [ i ] . call ( server , req , res ) ; } } } ) ; var count = 0 ; function onTransportRequest ( req , res ) { count += 1 ; console . log ( "REQUEST" , req . url , count ) ; if ( count === 1 ) { console . log ( "  Fail request" ) ; res . end ( "<An unparsable response>" ) ; return false ; } return true ; } }
Used to test re-connect when connect request fails.
Used to test re - connect when connect request fails .