0

In my search for a WebSockets library, I came across this website that provides Delphi and C# versions in download section. It grabbed my attention especially because the client-side of my application is developed using Delphi, and I'm trying to develop the server-side using C#.

Looking at the Chat sample for C#, I realized that it uses a wrapper class (sgcWebSocketLib) around the unmanaged DLL written in Delphi. Here is an excerpt from sgcWebSocketLib.cs:

public sealed class sgcWebSocketLib
    {
        private static volatile sgcWebSocketLib instance;
        private static object syncRoot = new Object();

        private sgcWebSocketLib() 
        { 
        }

        public static sgcWebSocketLib Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new sgcWebSocketLib();
                    }
                }

                return instance;
            }
        }

        ... //the rest is omitted 
}

and the code from Start button in Chat server (a typical WinForms application):

private void btnStart_Click(object sender, EventArgs e)
{
          string vOptions = "";
          ... //setting options according to UI values
          sgcWebSocketLib.Instance.Server_LoadOptions(vOptions);
          sgcWebSocketLib.Instance.Server_Start();
}

Now, here is the actual question: this Chat server uses a static property of sgcWebSocketLib class, and starts sending/receiving WebSocket stuff. Can I use the same approach in an ASP.Net application (WebForms or MVC)? Can I write the Chat server in ASP.Net using this wrapper class?

PS: I know there is SignalR and maybe others. But it has some limitations (IIS 8, Windows Server 2012 requirement for WebSocket) beside the unanswered communication problem with a Delphi VCL client.

Delphi.Boy
  • 1,199
  • 4
  • 17
  • 38

2 Answers2

1

Yes you can.

You will just have to pay attention to the Idle Time-out settings for your worker process (defaults to 20 minutes) as well as your Recycling settings (default is once every 29 hours). You may want to disable both settings if you want your application to never be recycled / go idle regardless of other parameters.

Recycling / idling will cause the worker process to shutdown, thus you'll lose any static variable and they'll have to be re instantiated when the process starts back up.

Check this answer for more info.

Community
  • 1
  • 1
Xeaz
  • 340
  • 4
  • 13
0

In IIS < 8 you won't be able of bind the WebSocket port to the same port than the web application (that is exactly what IIS8 can do)

Even with IIS8, the AppDomain is unable to recycle if there are WebSockets connected. So using the info that @Xeaz provided may be good idea. Usually I keep them in separate applications, since there is no point in mixing a connection oriented app (WebSockets), with a request-response one (regular HTTP). The only favorable point in doing that with IIS8 is the fact that both can share the port, but that is not really an issue aside of open/map an additional TCP port in the network, since cookies do not mind the port and WebSocket is not even affected by the SOP.

If the client is using the WebSocket protocol RFC6455 correctly, it should not matter which implementation is connecting to. I develop a websocket server for .NET/Mono 4.5 that works on Windows 7, take it a look if you go with the .NET server option.

vtortola
  • 34,709
  • 29
  • 161
  • 263
  • Thanks for your detailed answer. So if I want to use your library, I should just use a separate port for it? – Delphi.Boy Feb 10 '15 at 09:53
  • Right. For any WebSocket server that is not the IIS8 built-in one, you will need to provide a different port. – vtortola Feb 10 '15 at 13:51