3

I have an ASP.NET MVC 5 application and a NodeJs (Express+Socket.IO) application. In business scenario, I have to run NodeJS application inside an MVC application as a sub-directory.

for. e.g,

MVC: http://foo.com NodeJS: http://foo.com/node

I have hosted both applications in IIS 8 using IISNode(Latest version). Both application utilize websockets. Asp.net application utilizes SignalR and NodeJS utilizing Socket.IO.I have followed documentation available at https://github.com/tjanczuk/iisnode .

Issue is when socket.io.js loads on client side and tries to connect to server it returns 404-Not Found result. I have attached web.config for both applications and server.js of Node application. I suspect issue is with url rewriting.

here is server.js

// Load required modules
var http    = require("http");              // http server core module
var express = require("express");           // web framework external module
var io      = require("socket.io");         // web socket external module
var easyrtc = require("easyrtc");           // EasyRTC external module
var request    = require("request");
var consolidate = require('consolidate');
var https = require('https');
var fs = require('fs');

var options = {key: fs.readFileSync("easyrtc-key.pem"),cert: fs.readFileSync("easyrtc-cert.pem")};

// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
var webrtcController = require('./app/controllers/webrtcController');
httpApp.route('/rtc/webrtc/index').get(webrtcController.index);
httpApp.route('/rtc/webrtc/screensender').get(webrtcController.screenSender);
httpApp.route('/rtc/webrtc/screenreceiver').get(webrtcController.screenReceiver);
httpApp.use('/rtc',express.static(__dirname + "/static/"));
httpApp.engine('html',consolidate['swig']);
httpApp.set('view engine', 'html');
httpApp.set('views', './app/views');

// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(process.env.PORT || 1234);

// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":1});

// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);

For MVC application web.config is standard auto generated config file.

Below is my web.config of NodeJs application.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
        <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
    </handlers>
    <rewrite>
      <rules>
        <rule name="myapp">
          <match url="node/*" />          
          <action type="Rewrite" url="server.js" />
        </rule>
      </rules>
    </rewrite>      
   </system.webServer>
</configuration>

And below is the code for connecting to socket io.

  self.webSocket = io.connect(serverPath, {
      'connect timeout': 10000,
      'force new connection': true,
       resource: 'node/socket.io'
  });

All files from NodeJs application are loaded correctly, but somehow I am not able to connect to websocket.

Riya Shah
  • 31
  • 6
  • Sorry, I forgot to mention that it is an ASP.NET MVC application. – Riya Shah Jul 18 '14 at 14:38
  • @BenjaminTrent Thanks, But my issue is not related to webrtc. It's related to socket.io of NodeJS. – Riya Shah Jul 18 '14 at 14:46
  • Sorry, it was flagged for webrtc before...I suppose I need to learn to read :). – Benjamin Trent Jul 18 '14 at 14:48
  • @RiyaShah Are you able to resolve the problem? If yes than please let me know, i am facing same kind of problem. – Zaid Iqbal Dec 30 '14 at 06:06
  • @ZaidIqbal I've answered this over here http://stackoverflow.com/questions/15979904/iis-node-js-and-web-application-with-iisnode-not-configured-right/31482232#31482232 it has a full walkthrough of setup in IISNode with Virtual Directory and Socket.io, hope it helps. – peteb Feb 10 '16 at 20:35

0 Answers0