Wednesday, 11 July 2018

connect socket.io android client through a reverse proxy server to socket server

I'm trying to connect to a socket.io server running behind a Nginx reverse proxy. I have Nginx proxy server running with https config https://api.xxx.com. The node js socket.io server is running on another server with http config http://a.b.c.d:8081/app/v2.

In android side as a socket client, I'm using implementation 'com.github.nkzawa: socket.io-client:0.3.0.

Proxy is configured like this :

location /app/v2 {

            proxy_cache apicache;
            proxy_cache_revalidate on;
            proxy_cache_min_uses 2;
            proxy_cache_use_stale error timeout updating http_500 http_502
                          http_503 http_504;
            proxy_cache_lock on;
            proxy_cache_bypass $http_cache_control;
            add_header X-Proxy-Cache $upstream_cache_status;
            proxy_cache_methods GET;
            proxy_cache_valid 200 302 2s;
            proxy_cache_valid 404 1m;

            proxy_pass http://a.b.c.d:8081/app/v2;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;

    }

Node js Server :

socketio = socketio.listen(server);
socketio.set('transports', ['websocket']);
socketio.of('/app/v2/socketio/livefeed/').on('connection', function (socket) {
    console.log("device connected");
    socket.emit('clientAction','connected');
    socket.on('disconnect', function () {
        console.log("device disconnected");
        socket.emit('clientAction','disconnected');
    });
});

While trying to connect the android app to socket like this

`try { 
    mSocket = IO.socket("https://api.xxx.com/app/v2/socketio/livefeed/");
 } catch (URISyntaxException e) { 
    Log.d(TAG, String.valueOf(e)); 
 } 
 mSocket.connect();`

The socket client is not connecting to the socket.io server. How should I connect android socket client to socket server behind the proxy server?



from connect socket.io android client through a reverse proxy server to socket server

No comments:

Post a Comment