fredag 5 februari 2016

Making a streamed layer in Bing Maps and XSockets

In many cases we want information in real time specially in these IoT days. Socket solutions are not just for real time. It is also a question about scaling. Instead of the clients asking the server for information on interval, the server pushes information to the clients that are interested. So we need a server that can decide who should have the information when something changed.

XSockets is such a product. In this post I have build two map clients, one in web and one on WPF. Both map clients are built on top of Bing Maps. The scenario is we have a fleet with n number of vehicles that should be able to see each other in real time.
  1. To do that I emulate the vehicles and its positions in route files. 
  2. The server reads the route files and send each vehicles location to the subscribers
  3. The client gets the position and updates the location of the map
My friend Uffe Björklund help me with the server side. It basically consist of three entities. One class that is responsible to spin up threads for each route. One class that defines the route and one struct that holds the message. 

I am surprised of how easy it was to wire up the client side. With just three lines of code, we are good to go, with a subject subscription! The map client to handle the actual real time, with plotting, create new, update is just around 40 lines of code!

A screen shot from the web client.
A screen shot from the web client.

Why XSockets

The choice of XSockets is this demo was not only becasue it was easy to implement. It is also a choice for the future when the samples for realtime GIS will be more advanced. 
That's when XSockets will shine with the abilities missing in other frameworks:
  • Targeting clients based on state with lambda expressions
  • Quality Of Service
  • Retained messages
  • Auto-reconnect in combination with QoS and Retained messages (important for mobile clients)

Code

You can get the code from GitHub.

Inga kommentarer:

Skicka en kommentar