A socket.io client for node.js that can connect through a proxy server.
$ npm install socket.io-proxy
socket.io-proxy will automatically apply the proxy settings based on the http_proxy environment variable. If no proxy is defined, a direct connection to the destination will be established.
var proxy = require('socket.io-proxy');
var socket = proxy.connect('http://destination');
socket.on('connect', function () {
console.log('Socket connected');
socket.on('command', function (data) {
console.log('Received data');
});
socket.on('disconnect', function() {
console.log('Socket disconnected');
});
});
On Linux you can specify the environment variable in the following way: export http_proxy=http://proxy:8080
On Windows: set HTTP_PROXY=http://proxy:8080
You can also directly specify the proxy server using the init function.
var proxy = require('socket.io-proxy');
proxy.init('http://proxy:8080');
var socket = proxy.connect('http://destination');
socket.on('connect', function () {
console.log('Socket connected');
socket.on('command', function (data) {
console.log('Received data');
});
socket.on('disconnect', function() {
console.log('Socket disconnected');
});
});