This project is read-only.

Using WebSocket4Net with em-websocket ( Linux Debian )

May 8, 2012 at 1:31 AM


I was wondering if any of you guys can look into the compatibility with this specific server; seems lightweight and easy to use.

Until now I am able to connect to the server & receive data, but the connection terminates after around 30 seconds and I am unable to send data to the server.

You can find em-websocket here :


Any help will be very much appreciated !

Thank you in advance

May 8, 2012 at 12:56 PM

Did you catch any error by the event "Error" of the websocket client?

And did you find any logs in your websocket server?

May 8, 2012 at 1:14 PM

This is the log from the server :

[[:receive_data,  "GET / HTTP/1.1\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: MDJiOTcwNTUtNTZlYS00YQ==\r\nHost:\r\nOrigin:\r\n\r\n"]]
[[:inbound_headers,  "GET / HTTP/1.1\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: MDJiOTcwNTUtNTZlYS00YQ==\r\nHost:\r\nOrigin:\r\n\r\n"]]
[[:upgrade_headers,  ["HTTP/1.1 101 Switching Protocols",   "Upgrade: websocket",   "Connection: Upgrade",   "Sec-WebSocket-Accept: 0qsgD0HpP/J+Jui8XKOKr7ZGXTk="]]]
[[:sending_frame, :text, "Hello Client!"]]
[[:receive_data, "\201\201\350\375./\331"]]
[[:error, #<NoMethodError: undefined method `force_encoding' for "":String>]]
Error: undefined method `force_encoding' for "":String[[:closing, 3000]]

I am not sure if i catch the error properly in my client, here is how I do it :

websocket.Error += websocket_Error;


 void websocket_Error(object sender, EventArgs e)            {                                        MessageBox.Show(e.ToString());                                    }

May 8, 2012 at 1:21 PM

It seems that PING/PONG are not well implemented in your websocket server?

You can test your websocket server by:

May 8, 2012 at 2:42 PM

That website appears to be down :(

May 9, 2012 at 12:59 AM

I'm hitting this same issue as well (while connected to the chrome remote debugging websocket server.)  Here's the trace from the debugger right when the connection is unexpectedly closed:

System.Net.Sockets Verbose: 0 : [1560] Socket#2815801::SendAsync()
System.Net.Sockets Verbose: 0 : [1560] Socket#2815801::SendAsync(True#1)
System.Net.Sockets Verbose: 0 : [5568] Data from Socket#2815801::FinishOperation(SendAsync)
System.Net.Sockets Verbose: 0 : [5568] 00000000 : 89 93 78 EB 6A D4 4D C4-52 FB 4A DB 5B E6 58 DF : ..x.j.M.R.J.[.X.
System.Net.Sockets Verbose: 0 : [5568] 00000010 : 50 E7 4E D1 58 E2 58 BB-27                      : P.N.X.X.'
System.Net.Sockets Verbose: 0 : [5568] Socket#2815801::Shutdown(Both#2)
System.Net.Sockets Verbose: 0 : [5568] Exiting Socket#2815801::Shutdown()
System.Net.Sockets Verbose: 0 : [5568] Socket#2815801::Close()
System.Net.Sockets Verbose: 0 : [5568] Socket#2815801::Dispose()
System.Net.Sockets Verbose: 0 : [5568] Exiting Socket#2815801::Close()

Others have hit this as well (

I've added a PingPongEnabled property to my local websocket4net build to get me around this.

Perhaps the solution here is if a Close event is generated immediately after firing off an unanswered Ping message to fire an error about a missing Pong response.  That will at least give an indication of what's really going on.

May 9, 2012 at 3:08 AM

OK, I also want to add this property!

May 9, 2012 at 12:10 PM

A new property "EnableAutoSendPing" added!