11-04-2012, 03:19 PM
A simple peer to peer chat application using Windows Communication Foundation netPeerTcpBinding
A simple peer to peer chat application using WCF netPeerTcpBinding.docx (Size: 546.91 KB / Downloads: 131)
Introduction
As you all know Microsoft has launched .NET 3.0 with four very powerful foundations.
• WCF (Windows Communication Foundation)
• WPF (Windows Presentation Foundation)
• WF (Windows Workflow Foundation)
• Windows Cardspace
There is already a lot of material available on what is WCF, WPF, WF and cardspace. I am not going in details of these technologies. While exploring WCF, I came across many interesting things which are newly introduced. In my previous chat application using remoting, I was using an interface that is distributed across the client and server. There was an abstract class that was implemented at the client side. When the server wants to send a message to the client, the server should have the list of clients and something which is common in all clients. An interface implementation was the best way to achieve this. There was serialization, channels, protocols and much more in .NET remoting.
About the application
The simple WCF chat application I have written, uses netTcpPeerBinding. Using this binding, it is very easy to create a simple intranet chat application that can be used over intranet. You do not have to write much of the code and you do not even have to write
any special interfaces, classes at server side. Everything is encapsulated in:
How Are Nodes Identified?
The networks in P2P applications are also called meshes (or, sometimes, a mesh network), in that they are akin to a wire mesh. Each node in a mesh at a minimum has bidirectional communication capability with its neighbors. A cloud is a mesh network that has a specific address scope. These scopes are closely related to IPv6 scopes; the peers in a cloud are those that can communicate within the same IPv6 scope.
Name Resolution with PNRP
When one peer wants to resolve the name of another peer, it constructs the peer ID (as discussed earlier) and tries to find that entry in its cache for the ID. If a match is found, it sends a PNRP request message to the peer and waits for a response. This approach ensures that the target peer node, with which another peer is trying to communicate, is active in the cloud. If no match is found, an iterative process is used with the target peer that informs the sender of the peer that is the closest match to the ID that is trying to be resolved. At this stage, it is up to the original sender to send the same request to the matching peer as the one to which it was pointing. If the new peer to whom the sender was pointed is also incorrect, that in turn will return the next-closest matching peer to the sender, and so on.
What Is Peer Channel?
Until fairly recently, the P2P networking stack was mostly available only as unmanaged code, and a developer had to use C++ to be able to use any of it. This stack is part of Windows XP, and it has been improved as part of Windows Vista and Microsoft Windows Server 2008. Microsoft also has a managed code implementation for a subset of the functionality that is exposed by the P2P networking stack—called peer channel—and is released as part of WCF. Because peer channel is a “managed stack,” you can use any .NET language—making implementation of P2P applications easier and more productive, when compared to unmanaged code.
Conclusion
________________________________________
This article provides an understanding of the fundamentals of P2P and shows how to use the new features of WCF—allowing us to build P2P applications by using managed code in .NET Framework 3.0. The article also introduces the new features of managing P2P networks, including using People Near Me and Windows Address Book, both of which are new features that are released as part of Windows Vista.