WebSocket Server not working

Jul 9, 2010 at 12:50 AM


I recently started writing my own WebSocket server in C#, and have been running into issues.  I came across your server in my search for examples, but I can't seem to get yours to work correctly.  After I run your test app and launch Chrome I see the web interface, but it refuses to connect to the server correctly.  I can see that the server gets the original request and responds, but any interaction on the web interface results in this error: 

Error: INVALID_STATE_ERR: DOM Exception 11

My own code seems to have a similar issue.  I can see my server get a request and responds with what I think is the correct handshake, but the client immediately fires its "onclose" event.   I'm using Chrome v. 6.0.453.1, which uses version 76 of the WebSocket protocol.

Have you had similar issues with your server and the latest version of Chrome?  If I can get yours working, maybe I have a shot at figuring out what my own problem is.  Thanks!



Jul 9, 2010 at 1:38 AM
The "Initial POC release" doesn't support version 76. You could try to take a look at the latest source, its not very stable but it worked for my with a nightly chromium build a couple of weeks ago.
Jul 9, 2010 at 3:10 AM

Thanks for the response!  

I downloaded your latest source, and I got it working.  After comparing your output with mine, I was able to adjust a few things (the way I was sending data, and my "origin" response) and I got mine working as well!  Thank you!  I've been wrestling with this on and off for about a week.



Aug 24, 2010 at 11:58 AM

Hi Chris,

I'm encountering the same DOM Exception 11 problem with this code and the latest Dev-branch version of Google Chrome as you faced...

Could you possibly post the changes that you made to get it to work? If necessary I can PM you my email address.

Many thanks!



Sep 12, 2010 at 4:30 PM

Hi !

This sounds really very interesting!

I just downloaded:

 Aug 16 at 4:40 PM

but the server does not work. Not one client is able to connect to http://localhost:8080/
and the server is telling me, that the InfoServer tells me, that it is waiting on "" ..

Is there any configuration, I can apply to get some logging or something like this?
What else can I do to analyze the problem??

Would be really nice to get some help!


Sep 13, 2010 at 1:57 PM

there is a very basic, logging mechnism.

Try this: Nugget.Log.Level = LogLevel.Debug | LogLevel.Error | LogLevel.Info | LogLevel.Waring

If you are lucky your error will be printed.


Does it crash, or are the clients just not connecting?

Sep 14, 2010 at 8:17 PM

Hi !

Much thanks for your reply!


Astoundingly, your code:

[in WebSocketServer.cs]

IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, Port);  [~line 52]

creates a "binding" [???] to address "" on my machine !!
I currently have not tried to track this in a separate standalone exe ...
I just replaced it with the fixed IP of "" and this makes
the code running!

BTW:In typical server scenarios, it is not unusual, that the running
host has several addresses. To address this, a configuration option
is highly recommended!

my machine:

-Windows Server 2008 R2 {this is always x64!!}, en, all patches
-All Frameworks with all patches
-VS latest

Your code looks really very good [means also:Is difficulty for me,
to understand some details;This is with all the factories :-( ].

BTW, why do you use Unity?? If I see a configuration file, which
is ten time larger, than the program .... and not to understand ....

BTW, your logging class definition looks like that of "log4net".
So:Why not use it? You could define it as an interface to
let the final user decide, which object to load. I made really
very good experience with it [the final decision - one day - for
me was, that I can change the configuration at runtime!!!].

Do you have a roadmap for your future plans??

Anyways, much thanks for implementing and showing
the details and the new handshake!!!



Sep 22, 2010 at 7:49 PM
Edited Sep 22, 2010 at 7:51 PM

sorry for the late response.

Yeah i noticed the aswell, but it didn't make a difference on my machine, so i left it, your solution is noted, and I'll look into whats really going on

About the "several addresses", do you mean like several web applications running on the same host, or the same host having several IPs, or maybe several domains associated with it?

I use Unity to instantiate WebSocket objects when new connections are established, but I haven't made any configuration file, is it an auto generated file or where did you find it?

I thought about log4net, but I just haven't gotten around to implementing it yet.

I haven't got a roadmap, i have almost achieved what I initially wanted with the project, but there is still things that i would like to have done:

  • move the responsibility for starting the server out of the application
  • running the server as a stand alone app/service and plug applications in to it (as you do with web servers)
  • some way of interacting with instantiated WebSocket objects
  • more stability



Oct 5, 2010 at 3:46 AM

Same issue as mabra, i switched the IPEndPoint from "IPAddress.Any" to the actual server IP and it works now.  Thanks guys.

Dec 12, 2010 at 12:07 PM

Hi guys I have an update and a question now for the ip issue I updated the start function of the websocketserver.cs file here is the code:


        public void Start()


            // create the main server socket, bind it to the local ip address and start listening for clients

            ListenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            string HostName = Origin.Replace("\\","/");

            int i1 = HostName.IndexOf("://");

            if(i1<0) i1 = 0;

            else i1+=3;

            int i2 = HostName.IndexOf(":",i1);         // with port number

            if (i2 < 0) i2 = HostName.IndexOf("/", i1); // no port number with sub directories

            if (i2 < 0) i2 = HostName.IndexOf("?", i1); // no port number direct query string ??not shure if this is even allowed

            if (i2 < 0) i2 = HostName.Length;           // none of the above

            HostName = HostName.Substring(i1, i2 - i1);

            IPAddress[] Address;

            Address = Dns.GetHostAddresses(HostName);

            for (int i = 0; i < Address.Length; i++)




                    IPEndPoint ipLocal = new IPEndPoint(Address[i], Port);









            Log.Info("Server stated on " + ListenerSocket.LocalEndPoint);



first it does some parsing of the Origin to extract the host from it taking care of any additions it then gets the ip from the dns the try catch is to take care of any ipv6 that might be present (I had the problem when I ran the code on widdows7) any ways hope this helps.


now for my question how do I disconnect from the client from the server i.e. let the server do the disconnect not the client?


best of regards