Mono WebsocketClient

Jan 5, 2012 at 12:03 AM

First off, I'd like to thank for all the work on this project; it's great to have available and I'm getting great value from it.  I have a web socket server running successfully with client browsers connecting and sending/receiving data without issue.  I would now like to add a another client which is built using Mono.  I got the latest source, and was able to build the WebSocketClient.Mono project successfully.  Adding the built artifacts as references to my Mono projects is fine, but when I try to Open() the connection I get the following exception:

Could not load type 'System.Net.DnsEndPoint' from assembly 'SuperWebSocket.WebSocketClient.Mono'.

It seems I'm missing something simple here, but I'm just not seeing it.  Could anyone point me to any sample or have any pointers for implementing the client within Mono?


Jan 5, 2012 at 1:19 AM

Which version of Mono are you using?

Jan 5, 2012 at 1:42 AM

Sorry for not including that, mono -V returns:

Mono JIT compiler version 2.10.8

Jan 5, 2012 at 7:54 AM

I have fixed some issues for mono websocket client. And the latest client passed my test on Ubuntu (Mono 2.10.5).

Could you download the latest code again, and then build the mono websocket client?

Jan 6, 2012 at 1:10 AM

I pulled down the latest source I saw today (changeset 72182) and rebuilt binaries but still have the same exception at the same point - right when I call client.Open().  If it makes any difference, I am running this on Mac OS X Lion 10.7.2

Anything else I could provide that may be relevant?  Thanks for helping me through trouble.

Jan 6, 2012 at 2:03 AM

Do you have MonoDevelop installed?

If yes, please open the solution file SuperWebSocket.MonoTest.sln by MonoDevelop and then run NUnit test cases of project SuperWebSocketTest.Mono.csproj.


BTW, please also ensure NUnit addin has been installed for MonoDevelop.

Jan 6, 2012 at 3:02 AM

I do have MonoDevelop installed, version 2.8.5 and I was able to open the solution you directed me to, build, and run all tests without failure.  It seems perhaps I just have added a wrong reference, or failed to add a dependent reference perhaps?  I'm building and using the libraries 'SuperWebSocket.WebSocketClient.Mono.dll' and 'SuperSocket.ClientEngine.Mono.dll'

Jan 6, 2012 at 3:12 AM

Yes, you are correct. Can you just use the ouput of Test project which you just ran?

Jan 6, 2012 at 3:31 AM
Edited Jan 6, 2012 at 3:32 AM

I'm thinking I did something stupid and didn't mention a critical detail..  I am trying to develop for iPad and am using MonoTouch.  Sorry, I've just never used these tools for anything else and just didn't think of the difference.  I assume that must account for my inability to open a connection?  

Just in case it's not, replacing my projects referenced library with the output of the test sln build did not change the exception message or location.

My apologies for leaving out such details.  Do you have any suggestions on projects or reading to make a web socket connection from iOS?

Jan 6, 2012 at 3:32 AM

You should try SuperWebSocekt.WebSocketClient.Silverlight.

Jan 6, 2012 at 3:48 AM
Edited Jan 6, 2012 at 3:51 AM

When attempting to build the silverlight project, I immediately have a build failure stating:

Framework 'Moonlight / Silverlight 4.0' not installed

Looking to download the tools, I could only locate the browser plugin download.  This StackOverflow question here seems to indicate that there are some troubles building these projects using MonoDevelop.  

Are you using MonoDevelop to build this project, and if so, did it require any special "mangling" to get the project type recognized?

Jan 6, 2012 at 3:50 AM

Same error, but you can try build it by xbuild?

Jan 6, 2012 at 3:57 AM
Edited Jan 6, 2012 at 3:59 AM

That's new one for me, but I'm game to try!  Got a link or two pointing to some good information to get me started?  And thanks for helping out again, do appreciate the extra work.

Just reading:

For a project file to work with xbuild, it should have a target called "Build". xbuild doesn't restrict based on project types. So, if you have custom project types, or projects for a language that xbuild doesn't know about, it can still work as long as you have the relevant targets defined.

So it seems likely this will work, to at least get the build.  I'll dive in and see what happens.

Jan 6, 2012 at 3:58 AM

I am also researching about it and doing some experiment on my Ubuntu VM.

Jan 6, 2012 at 4:11 AM

Oh, you needn't build the Moonlight project, you'd better create a new MonoTouch project and then include all the source code.

Jan 6, 2012 at 5:16 AM

Ok, so I created the new project and brought in all the sources from either both socket client and silverlight projects.  I'm getting a build error now about not being able to load a type:

Mono.CSharp.InternalErrorException: Could not import type `SuperSocket.ClientEngine.TcpClientSession' from `SuperSocket.ClientEngine.Silverlight, Version=, Culture=neutral, PublicKeyToken=6c80000676988ebb'

I can see this class in the Assembly Browser looking at the SuperSocket.ClientEngine.Silverlight reference.  Any additional suggestions to build?  Maybe missing additional dependencies of SuperSocket.ClientEngine?

Jan 6, 2012 at 5:18 AM

You need to build your own SuperSocket.ClientEngine.

You can find the source code from

Jan 6, 2012 at 5:21 AM

Gotcha, thanks for info - and deeper down the rabbit hole we go :)

Jan 6, 2012 at 5:22 AM

It seems I should install MonoTouch and MonoDroid.

Jan 6, 2012 at 5:55 AM

Well I've got good news, I was able to get everything rebuilt properly and initiate a socket connection from the iPad simulator.  Haven't really done anything with it yet, but it looks like it should be usable.  Thanks for the help troubleshooting!

For reference, the original exception regarding DnsEndpoint was WebSocket.Open() method itself.  If  the IP address fails to parse, it tries to set RemoteEndpoint to a new DnsEndpoint; which doesn't seem to exist.  In order to compile I replaced this with a generic DNS lookup and then used the IP address rather than the class DnsEndpoint at all.  Here is the relevant code with original statement commented out.

if (IPAddress.TryParse(TargetUri.Host, out ipAddress))

    RemoteEndPoint = new IPEndPoint(ipAddress, TargetUri.Port);



//RemoteEndPoint = new DnsEndPoint(TargetUri.Host, TargetUri.Port);

var addr = Dns.GetHostAddresses(TargetUri.Host);

if (addr.Count() > 0)

RemoteEndPoint = new IPEndPoint(addr[0], TargetUri.Port);


Jan 6, 2012 at 5:59 AM

Great! Please use a IPv4 address, I am not sure it can support IPv6 address.

Jan 7, 2012 at 2:13 PM

Hi, the websocket client has been separated from SuperWebSocket to a new open source project named "WebSocket4Net":

Jan 9, 2012 at 11:40 PM

Very cool, funny I had just actually come across that on a different google search :)  I'll pull it down and give it a shot.  Chances are I'll be back on the boards over there because I know right now I'm having troubles actually sending messages.  We'll see if the new client helps out.

Thanks for all the work on these projects, i was pretty surprised/impressed to see a new project created so quickly!

Oct 31, 2012 at 4:08 PM

Hi, WebSocket4Net provides MonoTouch support now. You can have it by downloading the latest source code from the master branch.