Tag Archives: Windows Phone 8

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 :)

BlurryNews

I just released a simple WP8 client app for NewsBlur.com. For those who do not know, NewsBlur is a service that is competing with Google Reader. Or should I say was competing since Google is shutting Reader down.

Like many others, the news of Reader being shut down got me in search of replacement and in NewsBlur I have found a very good service that satisfies what I need from it.

Back to my app! The version that just got published in WP marketplace is very simple and gives you only the ability to browse and read stories within your feeds. I plan to add new functionality within the next few weeks. I have just submitted v1.1 for certification. This version brings the ability to signup for NewsBlur service, add new feeds, some performance improvements and other code changes to improve stability.

feeds

Using UriMapper

I bumped into an interesting issue with UriMapper on Windows Phone 8.

I followed the instructions here to redirect user to AccountPage.xaml page when they haven’t entered their credentials yet. After the user has logged in I tried to navigate back to MainPage.xaml, but I couldn’t and the app wasn’t throwing any exceptions.

Eventually I figured out that NavigationService.CurrentSource was saying the app was on MainPage.xaml even though I was on Account.xaml.

Turns out that when mapping with UriMapper that does not affect NavigationService.CurrentSource property, the property remains set to the value of original Uri. And at app startup that was the Uri as configured in WMAppManifest.xml:

    
      
    

My UriMapper implementation was like this:

    public class PageUriMapper : UriMapperBase
    {
        private readonly MainViewModel _viewModel;

        public PageUriMapper(MainViewModel viewModel)
        {
            _viewModel = viewModel;
        }

        public override Uri MapUri(Uri uri)
        {
            if (!_viewModel.Settings.IsValidUsername)
            {
                return new Uri("/AccountPage.xaml", UriKind.Relative);
            }
 
            return uri;
        }
    }

So I decided to set the startup page in WMAppManifest.xml to a page that does not exist in my project:

    
      
    

I modified my UriMapper to be like:

    public class PageUriMapper : UriMapperBase
    {
        private readonly MainViewModel _viewModel;

        public PageUriMapper(MainViewModel viewModel)
        {
            _viewModel = viewModel;
        }

        public override Uri MapUri(Uri uri)
        {
            if (uri.ToString().Contains("StartPage"))
            {
                if (!_viewModel.Settings.IsValidUsername)
                {
                    return new Uri("/AccountPage.xaml", UriKind.Relative);
                }
                else
                {
                    return new Uri("/MainPage.xaml", UriKind.Relative);         
                }
            }
 
            return uri;
        }
    }

And voila! My navigation began to work since “StartPage.xaml” != “MainPage.xaml” :)

WP8 Emulator Weirdness

I bumped into an issue that IMHO shouldn’t be an issue today. Not quite sure if it is related to portable HttpClient library that I am using, but I am going to put it out there is someone else bumps into the same issue.

I am writing a simple NewsBlur client for Windows Phone 8 and my app works well on my device now so I wanted to see how it looks in other resolutions supported by WP8. And to my surprise every request I made through HttpClient library returned status 404. Huh?

Turns out that IE on the emulator isn’t configured when you run the emulator. So when I tapped on IE I was presented with this:

wp8-ie-settings

Once I had that out of my way and I tried to run my app again it worked. Huzzah!

UPDATE:

The above no longer works. I seem to have bigger issues with the emulator. Sigh… I’ll try┬áre-installing.