Using Node.JS With ASP.NET WebForm and Socket.IO

2.4k Views Asked by At

The first question I have is, is it possible to use Node.JS and Socket.IO inside of a ASP.NET webform and .Net web application?

What I am trying to do is show real-time data, and I want to do this using node.js modules.

I understand the client side code for node.js but how do I implement the server side, i.e. exactly where do the server side code go and how do i call it?

here is what i have so far: myfiddle

<head runat="server">
<title>Logger</title>
  <script src="/assets/js/chosen.jquery.min.js"></script>
<script src="/assets/js/date-time/bootstrap-datepicker.min.js"></script>
 <script src="/Scripts/js-cookie.js"></script>
<script src="/Scripts/socket.io-1.3.5.js"></script>
<script src="/Scripts/displaylogs.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="container">

</div>
</form>
</body>


$(document).ready(function () {
// start by the connection with socket.io
var socket = io.connect('http://localhost:8080');
var container = $('#container');

// makes every new chunk of data it receives displayed inside a div.
socket.on('new-data', function(data) {

    var newItem = $('<div>' + data.value + '</div>');

    container.append(newItem);
});
});
1

There are 1 best solutions below

3
On BEST ANSWER

It's definitely possible to use node in a .NET app. You have to configure IIS to route requests to the node process when a node file is requested. The best way is usually to put all your node code in a subdirectory just for node and let IIS route all requests for that subdirectory to the node process.

Take a look at IISNode. It's the same IIS extension they use on Windows Azure.