SignalR client on Mono for Android

While SignalR is a great library for push notifications it has one “flaw”. There is no included Android client implementation currently, and by Android I mean Mono For Android. Luckily SignalR is an open source project and I decided to see how hard is to make it Mono For Android compatible. It turns out that it is pretty simple.

Here is the recipe (tested on Mono For Android 4.0.x):

  • SignalR depends on Newtonsoft.Json library (free, open source) developed by James Newton-King. Again, there is no Android port included with the original library but there is a port that works fine on Mono For Android. Get it here.
  • Get SignalR client sources. Create new Mono For Android class library and import all (WindowsPhone version of the project) files. Add WINDOWS_PHONE conditional compilation symbol to Project Properties/Build. Then reference the Newtonsoft.Json libary.
  • Mono For Android is currently missing TaskExtensions class required for unwrapping tasks. Get the sources for this class here. I assume it will appear in Mono For Android sooner or later. Add this class to the library and add proper using statements if/where necessary.

That’s it. You are now ready to receive SignalR push notifications.

Here is how you create a PersistentConnection (server part), and here is client code (that runs fine on Mono For Android).

Download the libraries and sources below

 MonoForAndroid.SignalR.Client.zip (1.40 mb)

5 thoughts on “SignalR client on Mono for Android

  1. Many thanks for this article. I have to implement asynchronous webservices on Android in my Thesis and was stuck since wcf doesn't support this on Mono right now. Did you think of contributing your android project to SignalR? It would be nice to see an "official" version of it.

  2. Well how about asking SignalR if they could include the project in their solution? Or point them at least at this post, perhaps they know how to include it. I didn't contribute to a project so far.

    1. I asked SignalR guys and they say I'd have to handle Github, keep project in sync with the original SignalR etc. Quite a lot of work and not much time at my disposal…

  3. Perhaps they don't have mono to get things done. I'll consider doing it.

    I got a question though: did you get Hubs to work with the Android Client? I have serious trouble to get the connection started, it just won't work. It could be an IP Problem, Hubname problem, or server problem. But nothing seems to work. So I wonder if it's a problem with mono for android. Would be nice if you could test that issue.

Leave a Reply