Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 1.55 KB

README.md

File metadata and controls

63 lines (45 loc) · 1.55 KB

socket.io-proxy

A socket.io client for node.js that can connect through a proxy server.

Build Status

Installation

$ npm install socket.io-proxy

How to use

Based on environment variable

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

Explicit proxy definition

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');
    });
});