On the internet to see a lot of programs (QQ, Azureus, Ants, PPStream) have achieved peer-to-peer, previously felt that the technology is very advanced. Through this period of study only found that the simple realization of peer-to-peer in the LAN communication is very easy, but to achieve the external network penetration (NAT) feel very difficult. Recently looked at the Azureus and emule source code, respectively, Java and C + + version, I am not familiar with the two languages, looks very laborious. Finally, according to VC + + implementation of the P2pdemo program for the revision, according to the design of C # written a demo. Through testing, multiple clients can achieve end-to-end work on the LAN from the server. The situation of the extranet to through the router, see Azureus to implement UPnP port mapping, in CodeProject download a UPnP source look, test results are not enabled UPnP router. The result is now depressed, do not know how to test the next step, is not using UPnP to achieve the port automatic mapping success can be achieved like QQ communication.
The following is a description of the program:
1. public class
The public class mainly defines some package structures
A, Packet.cs
[Serializable()]
public abstract class Packet
{
/// <summary>
/// 命令类型
/// </summary>
/// <returns></returns>
public virtual int GetCommandType()
{
return -1;
}
/// <summary>
/// 用户名
/// </summary>
public string UserName
{
get;
set;
}
public Packet()
{ }
public Packet(string username)
{
this.UserName = username;
}
}