Tag Archives: Mono

Talking to node.js socket.io from Monotouch and WP8

I am writing a game and the server side for my game is written in node.js. I am also using socket.io websockets.

Writing a simple node.js server that uses socket.io is a piece of cake. Using it from Monotouch or WP8 howewer is not. There is a .NET library that works just fine on other platforms but unfortunately it uses dynamic features (dynamic keyword and so on) in .NET which causes problems when you try to use it from Monotouch – apparently Apple imposed some limitations on JIT compilers and as a result Monotouch does not have support for dynamic features.

Fixing it in Monotouch turned out to be relatively easy. I replaced all occurrences of dynamic with object – I am not really sure why dynamic was used in the first place as there doesn’t seem to be a reason for having it in there. I also needed to replace Json.NET with a version that can be used with Monotouch (this is available from Xamarin Components) and make some changes to other libraries that socketio4net uses (websocket4net and supersocket.clientengine).

Making this very same code work on WP8 was far trickier, I needed to implement a number of collections that are used by socketio4net and are not available in WP8 flavor of .NET. I was in luck as copying source files from Mono did the trick for most of them.

All this is on Github, see https://github.com/ayls/socketio4net. Now you can create Monotouch and WP8 apps that can talk to socket.io :)