The Peer-to-peer network communication program implemented by C #

Source: Internet
Author: User

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;
        }
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.