6

I am writing a ASP.Net MVC app that connects to a SQL database and uses existing C# libraries I have.

I also have a TCP server Windows application that sends/receives TCP messages via XML. I have successfully setup node.js and socket.io to handle all this and have a html page that sends/receives messages to the server. Node.js is serving up the html page at the moment. The XML is converted to JSON when sending/receiving data.

I am planning on setting my MVC app to serve the page up but was just wondering what your thoughts are on this use of cross framework setup. Does it seem viable and a good solution for handling TCP messages and sending it to the browser? I have also read about iisnode for hosting node in IIS which I guess would be a good idea for my setup. What are your thoughts on this?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jon
  • 38,814
  • 81
  • 233
  • 382

1 Answers1

3

You basically have two websites. One is your ASP.NET MVC website. and the other is a web client for your TCP windows application.

Since they are disjoint it will work fine.

You may want to have that web client's html server through ASP.NET MVC and only run a websocket server on node.js though. You may need to do some proxying to get the same origin to work.

If you server your HTML page from a webserver running IP Y, port X and then try to talk to the node.js websocket server running on IP Y, port X + n it may violate the same origin restriction.

This means your basically loading a socket.io client from server A and trying to talk to server B. The web page doesn't know you own both of these servers.

The solution would be a proxy, you proxy all requests to server A and B but since they all go through the proxy it doesnt violate the same origin.

As for proxy, nginx is one. There is a node-proxy. And IIS might be able to proxy it for you (Although I doubt IIS makes a good proxy)

Raynos
  • 166,823
  • 56
  • 351
  • 396
  • I will have one website and will have one web server dishing up the pages but you are right that I have a web client/socket server for the TCP application which sends data to the web page. – Jon Sep 21 '11 at 10:23
  • Do you know anything about iisnode? – Jon Sep 21 '11 at 10:24
  • 3
    @Jon iisnode sounds like an abomination, I would stay away from it. The only use case is tricking sys admin / management into installing node.js in a windows shop. – Raynos Sep 21 '11 at 10:25
  • What do you mean about proxying in your answer? – Jon Sep 21 '11 at 10:36
  • @Jon see edits. A proxy is only neccessary if you don't server the web client for your socket.io from node. Again it's a mix up whether it's more elegant to serve the web client from node or ASP.NET MVC – Raynos Sep 21 '11 at 10:41
  • I think I would need proxying no matter what unless my hyperlinks to the pages that have the socket.io client on them specify a different port?? – Jon Sep 21 '11 at 10:44
  • Although the 2 servers won't be talking to each other they will have the same IP but different ports so is proxying really needed – Jon Sep 21 '11 at 10:47
  • @Jon You don't need a proxy, you probably want one. A node web server will work with socket.io out of the box without a proxy. You can just expose two ports to the public and set up your domains properly. – Raynos Sep 21 '11 at 10:49
  • I'm afraid you've lost me on ths one, probably cause I dont really understand fully why I would want a proxy :) In my page I it would be served up by mydomain.com/socket/mysocketclient and then in the javascript that refers to the socket server I assume its connection value would be mydomain.com:1234. I think your saying that a proxy would alleviate the need for me to specify the port number?? – Jon Sep 21 '11 at 10:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/3658/discussion-between-raynos-and-jon) – Raynos Sep 21 '11 at 11:09