SocketCluster / socketcluster-client

JavaScript client for SocketCluster
MIT License
291 stars 92 forks source link

How to connect to multiple hosts on client? #91

Closed navjotghotra closed 6 years ago

navjotghotra commented 6 years ago

I am trying to connect to multiple hostnames with different ports. I know how to connect to one using socketcluster.connect(options) where options is an object like this -

    var options = {
        hostname: '127.0.0.1',
        port: 8019,
        rejectUnauthorized: false, 
        secure: true
    }

How can I add more hostnames to the object? I tried creating an array and add more objects to it - var options = [{ hostname: '127.0.0.1', port: 8019, rejectUnauthorized: false, secure: false },{ hostname: 'abc', port: 8019, rejectUnauthorized: false, secure: true }] but that gives an error of -

WebSocket connection to 'ws://localhost:5000/socketcluster/' failed: Connection closed before receiving a handshake response

jondubois commented 6 years ago

@navjotghotra Each client socket can only have a single host name. You can use a domain name as the host name and then use a DNS system to do some sort of round-robin IP selection behind the scenes... Or you can create multiple sockets; one for each host.