Windows Phone 7.1 (Mango) – Socket Sample

As some of you might know, I’m currently writing a book called “Windows Phone 7 in Action” with two amazing authors for Manning. We managed to put new sample for Socket to our git repository yesterday. Our small program has the conversational style chat message view which is similar to the SMS view on Windows Phone (Mango) and socket classes ( Tcp Unicast, Udp Unicast and Udp AnySource Multicast). In order to make our code simple, we didn’t add any validation logic in our code. We hope that our sample might help for those who are new to Windows Phone socket programming.

You might say that there are some examples for sockets in MSDN already but one important thing to note is that the author of those samples encourages developers to use ManualResetEvent. It’s so misleading. I don’t really understand why they did that. But all I can do is to give them feedback so I (and a few other MVPs as well) submitted the feedback a few months back but nothing changed until now.

Anyway, let’s get back to our sample code. Here is the folder structure and a bit of details about samples.

Clients

  • ChatTcpUnicast : This sample uses Tcp Unicast so you will have to run the Tcp Server to test the code.
  • ChatUdpAnySourceMulticastClient : This is UdpAnySourceMulticast sample so you don’t need to run any server. It’s just peer-to-peer.
  • ChatUdpUnicast :

Servers

  • TcpSocketServer
  • UdpSocketServer

You can download the full source from this link below.

  • Gitwp7.1 socket
  • git clone git@github.com:michaelsync/Michael-Sync-s-blog-sample.git

Please feel free to let us know if you have any question or anything for improvement. We are sorry that we couldn’t write all those explanations here. If you are interested in detailed explanation, please get our book “Windows Phone 7 in Action” from Manning. Thanks.

UPDATE: 

Note that I didn’t use appbar which is not bindable and doesn’t have Command.. so you gotta touch twice to send the message .. You may want to replace with this bindable appbar http://www.maxpaulousky.com/blog/archive/2011/01/10/bindable-application-bar-extensions-for-windows-phone-7.aspx

One thought on “Windows Phone 7.1 (Mango) – Socket Sample

  1. Hi.I have problem running a simple native c++ udp socket client and/or server on wp8 emulator which run successfully on windows projects.Searching the web for days in the internet didn’t help me at all to find a solution
    I would appreciate if you could give a hint about that.
    thank you

Leave a Reply

Your email address will not be published. Required fields are marked *