Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client is not receiving event from SocketIO via IIS Node

I have a web application which is making a socket connection with a NodeJS server hosted via IIS Node. The connection seems to be made properly as I resolved a 404 polling error on the client that I was initially having. However now, it looks like the client is not receiving socket events from IIS Node.

My theory is that because IIS Node is acting like a proxy, the event sent back to the client is stopping somewhere at the IIS Node level.

exports.register = function(socket) {
    User.schema.post('save', function (doc) {
        console.log("Save socket");
        onSave(socket, doc);
    });
}

function onSave(socket, doc, cb) {
    socket.emit('User List Update', doc);
}

In Node, the above event fires, but it is not received on the front end.

The client looks like this:

var socket = io.connect("http://myinternallyhostedserver:7777/reception");

socket.on('User List Update', function () {
  console.log('Received socket event!');
  if (vm.enableAlert) {
      vm.alertSound.play();
  }
  vm.getUsers();
});

My web.config file looks like this:

<configuration>
    <appSettings>
        <add key="virtualDirPath" value="/reception" />
    </appSettings>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="server/app.js" verb="*" modules="iisnode" />
        </handlers>
        <iisnode enableXFF="true" />
        <webSocket enabled="false"/>
        <rewrite>
            <rules>
                <rule name="reception">
                    <match url="/*" />
                    <action type="Rewrite" url="server/app.js" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Running all of this on my local machine works properly. Socket events are sent and received. Adding IIS Node into the workflow seems to be where it stopped working. Any help would be greatly appreciated.

like image 578
developthewebz Avatar asked Oct 11 '17 15:10

developthewebz


1 Answers

While using socket.io with proxy pass , you need to pass some variable like upgrade etc. I didnt even try using iis to proxy pass socket.io but I came across some problem in apache proxy pass . Therefore I choose nginx to proxy server.

Maybe you need to write this kind of parameters in iis , alternatively you can use nginx as a proxy pass server.

location / {
        proxy_pass http://socket_nodes_2/doSomething;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

upstream socket_nodes_2 {
    server 192.168.1.155:1338;
    server 192.168.1.156:1338;
}
like image 58
Emre Karataşoğlu Avatar answered Sep 25 '22 03:09

Emre Karataşoğlu