Client is not receiving event from SocketIO via IIS Node
Asked Answered
G

1

7

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.

Glenine answered 11/10, 2017 at 15:0 Comment(2)
See if this helps? github.com/tjanczuk/iisnode/issues/402, github.com/tjanczuk/iisnode/issues/268 and blog.novanet.no/…Pugh
can you Please Add Your Server.js With socket.on Event I am only seeing Socket.emit () eventSosna
A
2

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;
}
Adolphus answered 23/10, 2017 at 14:50 Comment(1)
I want to add that if you use proxy pass with load balancing as me, you need to handle session on redis or memcache ^^ , by the way the published event received both of nodes ;)Burglar

© 2022 - 2024 — McMap. All rights reserved.