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.
- 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 :
You can download the full source from this link below.
- Git : wp7.1 socket
- git clone firstname.lastname@example.org: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.
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