Steve Spencer's Blog

Blogging on Azure Stuff

Imagine Cup NE

Just finished at the Hacking Imagination event in County Durham. My role was to help mentor and encourage the students from Universities and Colleges in the North East of England to help them to develop their ideas for their Imagine Cup entries.

The event was held in a secret location in county Durham and the students were bussed in.

DSC_0163

A number of us from Black Marble attended and performed workshops in Migrating to Azure (me), ALM/TFS (Richard), WPF, SilverLight, Phone 7 101 (Leon), Planning Poker (Me, Leon) & Software War Stories/How to Run a Software Business(Robert, Me). The students were all enthusiastic and asked a lot of sensible questions. The students were put into teams if they hadn’t already formed them, which was interesting to watch as an outsider as it was a bit like a recruitment fair with students walking around from team to team where both sides were deciding whether the person or the team were a good fit. This seemed to have worked well with everyone having a team. the age and skill levels range from college students doing their A levels to MSc.

The aim of the two days was to get the teams in a position where they had an idea that is more than just a software app with a good justification for it. This was a difficult task for a lot of teams as they either had a technology solution and tried to find a problem to solve or a really wide problem that they were trying to solve. Most of the discussions were around getting the teams to think about the whole solution including who it is aimed at and how they are going to deliver it rather than just the software side of the solution. It was also about getting some of the teams to focus down on to a specific area rather than being general. Some of the ideas changed each time I spoke to the teams!!

The (long) 2 days ended with each of the teams doing a presentation of their ideas to the whole group. The whole 2 days was enjoyable and the students seemed to gain a lot from the experiences, bringing some out of their shells.

The thing that impressed me most was the amount of young talent that is around and the abilities they have. One group of students were from a 6th form college doing their A Levels/BTEC and the college had around 15 – 20 attendees, all working hard to deliver a good thought through ideas and presenting their ideas to a group of about 50 people. That is something I used to avoid as much as possible when I was at that age. It is this talent that is the future of IT. Credit must go to the teacher/lecturer who has encouraged this amount of A Level/BTEC students to attend an event like this. Its not an easy task to get teenagers to do anything (he says from experience).

Events like the Imagine cup helps these guys (and girls) to gain real world experience and advice from experts in the field. Getting a chance to influence and help this talent has been rewarding for me and I want to try to help some of these young people more. So thanks to all the people who organised and mentored the event and thanks to the students that attended.

There was a lot of information being passed around and to finish off this post, I’ve put together a list of some of the areas that we were talking about in my sessions. I hope they are useful.

Video of wiring the Windows Azure Access Control service into an ASP.NET website. My bit is at the end and its a no code demo to allow users to login to you website using Live, Google or Yahoo accounts.

The Windows Azure Platform training Kit

The Windows Identity training Kit

Windows Azure Pricing& MSDN subscription allowances

Team Foundation Server in the Cloud

Books

Don't Make Me Think!: A Common Sense Approach to Web Usability : Steve Krug (ISBN: 0321344758)

The Art of Unit Testing – Roy Oshrove

Pingbacks and trackbacks (2)+

Loading

Steve Spencer's Blog | Scrum Overview

Steve Spencer's Blog

Blogging on Azure Stuff

Scrum Overview

Scrum is a process to help with the day to day running of projects. From my experience of running projects using scrum I have written an overview document. This is probably not pure scrum but it works and has practical advise. The overview is written from the team leaders perspective and may be useful to new team leaders or existing team leaders who are new to scrum.

overview - Scrum overview (pdf).

Loading

Steve Spencer's Blog | Proximity Communication with Windows Phone

Steve Spencer's Blog

Blogging on Azure Stuff

Proximity Communication with Windows Phone

In my previous post I talked about using NFC to communicate between devices and hopefully gave you an introduction to the capabilities of NFC. This post will cover the Proximity API in more detail and show you how to set up a persistent connection between two Windows Phones which will allow you to communicate without needing to keep tapping phones together to transfer data. Windows Phone and Windows 8 apps can utilise the .NET Proximity APIs to connect together apps without needing to be connected to the same network. Proximity uses BlueTooth or WiFi Direct (Not on Windows Phone 8) to make a persistent connection between the two devices and utilising StreamSockets to communicate between the two devices. The proximity API uses a PeerFinder to browse for proximate devices or to sit and wait for a Tap to occur.

The first scenario is to set your app in a mode where it can accept incoming Tap requests, then set up a connection between the two devices.

The second scenario is to start your app and then browse for other devices that are running your app and which are within range of your device.

Both scenarios use the PeerFinder classes to initiate the communication.

Scenario 1: TAP to send

PeerFinder has a number of static methods and events that allow you to wire up your app to respond to peer requests. In the Tap to send scenario your app needs to wait for a tap to occur and then initiate opening up the communications channel. PeerFinder has an event called TriggeredConnectionStateChanged which is triggered upon a Tap initiation and is fired for each event state change that occurs. Upon successful connection an open socket is returned which can then be used for communication between the two devices. Once the event is wired up the PeerFinder needs to be started. This is required for both scenarios. You will also need to ensure that the Proximity and Network capabilities are added to you app manifest.

// Wire up the event and be notified when a device is tapped
PeerFinder.TriggeredConnectionStateChanged += PeerFinder_TriggeredConnectionStateChanged; 
// Start finding peer apps, while making this app discoverable by peers
PeerFinder.Start();

The event handler is as follows:

<Insert Code>

PeerFinder.TriggeredConnectionStateChanged += PeerFinder_TriggeredConnectionStateChanged;
.
.
.
private void PeerFinder_TriggeredConnectionStateChanged(object sender, 
                                            TriggeredConnectionStateChangedEventArgs args)
{
    switch (args.State)
    {
        case TriggeredConnectState.Listening:
            // Connecting as host
            WriteStatusMessage("Listening");

            break;
        case TriggeredConnectState.PeerFound:
            // Proximity gesture is complete and user can pull their devices away. Remaining work is to 
            // establish the connection using a different transport, like TCP/IP or Bluetooth
            WriteStatusMessage("Peer Found");

            break;
        case TriggeredConnectState.Connecting:
            // Connecting as a client
            WriteStatusMessage("Connecting");
            break;
        case TriggeredConnectState.Completed:
            // Connection completed, retrieve the socket over which to communicate
            if (!StreamSockets.ContainsKey(args.Socket.Information.RemoteHostName.CanonicalName))
            {
                StreamSockets.Add(args.Socket.Information.RemoteHostName.CanonicalName, args.Socket);
                _currentConnectionID = args.Socket.Information.RemoteHostName.CanonicalName; 
            }

            WriteStatusMessage("Connected");

            // start the listener off on a new thread
            _Receivethread = new System.Threading.Thread(new ThreadStart(ReceiveData));
            _Receivethread.Start();

            break;
        case TriggeredConnectState.Canceled:
            WriteStatusMessage("Canceled");

            break;
        case TriggeredConnectState.Failed:
            // Connection was unsuccessful
            WriteStatusMessage("Failed");
            break;
    }

}

The code above covers the whole connection process and the important part is the TriggeredConnectState.Completed state. It is in this state that we are presented with a valid socket and in the case of Windows phone 8 a BlueTooth connection between the two phones has been created with an open StreamSocket to enable the communication. We also setup a thread that listens on the socket for incoming data to allow two way communication to occur. Both apps need to go through this process and setup a mechanism for sending and receiving data. PeerFinder will find all apps with the same id but it is possible to find other apps that are compatible with your application by adding alternate application identities by adding the information to the AlternateIdentities collection. However, when I tried to add an alternate Windows Phone 8 identity, the key "WindowsPhone" was not accepted and it looks like only Windows can be used.

Using this method the connection is established when the Tap is initiated but this can get tedious if you want to connect to a number of devices. In this case Scenario 2 would be better.

Scenario 2: Browser for devices

It is also possible to connect to compatible applications directly without the need to Tap devices together. The act of starting a compatible app will allow the device to be discoverable to other devices running the same app. PeerFinder is again used but this time we need to wire up a different event, ConnectionRequested. This is fired when a device attempts to connect and allows the connection to be made. When ConnectionRequested fires, the connection information of the device trying to connect is passed through with the EventArgs and PeerFinder.ConnectAsync is called. On successful connection then the same methods for sending and listening are used as in scenario 1.

PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested;
// Start finding peer apps, while making this app discoverable by peers
PeerFinder.Start();
.
.
.
async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
{
    WriteStatusMessage("ConnectionRequested");

    StreamSocket socket = await PeerFinder.ConnectAsync(pi);
    PeerConnected(socket);
}

We've wired up the app so that it is capable of receiving a connection from a remote device, we now need to initiate the connection.

Again this is done using PeerFinder and the method FindAllPeersAsync. Will return a list of applications that are compatible which can then be connected to individually. Only one Peer connection can be made at any one time so you will need to connect, send data and then disconnect before moving on to the next peer. Iterating through the list of PeerInformation that is passed.

IReadOnlyList<PeerInformation> readOnlyList = await PeerFinder.FindAllPeersAsync();
PeersFound(readOnlyList);
.
.
.
private async void PeersFound( IReadOnlyList<PeerInformation> readOnlyList)
{
    foreach (PeerInformation pi in readOnlyList)
    {
        StreamSocket socket = await PeerFinder.ConnectAsync(pi);
        PeerConnected(socket);
        return;//for now lets just deal with the first connection
    }
            
}

private void PeerConnected(StreamSocket socket)
{
    OnConnectionStatusChanged("Connected");

    // Do send/receive stuff here

}

For a full worked example see here and for more details of messages

You will need to look into the capabilities of each device as some will only connect via BlueTooth and others only using WiFi Direct and you can use the properties of PeerFinder to control which mechanism you would like to use

PeerFinder.AllowBluetooth = true;
PeerFinder.AllowInfrastructure = false; 
PeerFinder.AllowWiFiDirect = false;

The two posts should now give you information about how to connect phone apps together and provide some insight into how you can connect other devices and provide a rich set of functionality to you apps that previously required backend services to communicate.

Loading