LearnBoost/socket.io-client — pull request #484 by helenst (2012-10-30 10:03:57+00:00)
Title: Added extra option, 'ports', allowing ports to be configured on a per-transport basis

This allows you to talk to a socket.io server through a different port depending on protocol. This is my solution to the various issues I encountered around reverse proxying, multiple ports etc. when attempting to integrate socket.io with a web based game I was working on. This blog post (not mine) talks more about those things: http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/ (but I've ignored load balancing and SSL for now)

In my setup, I've got a default port of 80 with overrides for websocket and flashsocket on port 8080. More modern clients with no port blocking can talk websockets. Older browsers, or those on restricted networks, fall back to xhr-polling on port 80, which is reverse proxied to the same server via nginx. It's important to have the handshake on port 80 so that the initial negotiation can take place even if the other ports are blocked.

Usage example:

var address = "/endpoint"; // take current host, port etc.
var opts = {
ports: {
"websocket": 8080,
"flashsocket": 8080
}
};

var socket = io.connect(address, opts);