Hosting via IIS (in an ASP.Net MVC app)

Nov 20, 2010 at 2:31 AM
Edited Nov 20, 2010 at 2:42 AM

I'd like to use Nugget to add websocket server capabilities to an existing ASP.Net MVC website. Ideally something like this:

  1. User browses to domain.com/chat
  2. Asp.Net MVC delegates out to the ChatController, which renders the Index view to the client.
  3. JavaScript code that was rendered to the client initiates a websocket connection to domain.com/websockets/chat (on port 80).

I'm having trouble getting this to work. What I've tried so far is:

  1. create a new Asp.Net MVC webapp
  2. copy Server.cs from Sample 01 (ConsoleApp) to the MVC app
  3. move the code from the Server.cs console class ("Server") to the global.asax's app_start event
  4. save the instance of the nugget server created in app_start in a static property
  5. set the proj file to always launch the webapp on the same port (50596) and update the javascript & new WebSocketServer(...) code to reflect the port change
  6. move the javascript & HTML from Sample 01 to Views/Home/Index.aspx

At this point running the app works in so far as it doesnt throw any exceptions, but when the javascript executes it receives a 404 from ws://localhost:50596/consoleappsample, presumably because it isn't playing nice with Routing.

Any ideas how to support this scenario?

Edit: Before anyone points it out, yes I'm aware a webapp in IIS can be reset essentially at anytime. I'm cool with that in my scenario. :-)

Coordinator
Nov 23, 2010 at 8:41 PM
Edited Nov 23, 2010 at 8:44 PM

Are you setting the location/origin right when instantiating the server?

var nugget = new WebSocketServer(8181, "null", "ws://localhost:8181");

here 8181 is the port the server is running on, nullis the origin to allow connections from (nullmeans the file system) and ws://localhost:8181 is the location (the place the server i running).

You will probably need something like:

var nugget = new WebSocketServer(80, "http://localhost:50596", "ws://localhost:80");

if you are running the server on port 80 and the web app on port 50596


try to take a look at the web app fork: https://hg01.codeplex.com/forks/mdroz8/webchat Its a little dated, but maybe it can help?

 

EDIT: formatting