Hi I've been looking for information on how I am able to connect to a websocket service when my asp.net mvc application starts up. I'd like to ensure that there is only one instance of the socket connection and be able to reference this in my controllers.
I've seen a number of articles talk about web page to server, however, I'm trying to connect my server to another server.
I'm looking for a code example of how this can be achieved.
If you're doing ASP.NET then SignalR is an excellent (and probably recommended) approach - http://www.asp.net/signalr.
If you're trying to do a server - server socket connection, a controller is not the best place to do this. If this needs to happen when you're application starts, you should use your Global.asax Application_Start method:
void Application_Start(object sender, EventArgs e)
{
// Create socket connection here
}
There's good examples about creating socket connections here.
Keep in mind, you will need to handle connection, disconnection, reconnection etc.