. Net PNRP programming implementation

Source: Internet
Author: User

I. P2P resource release process
Resource publishing is the process in which a resource owner registers resources to the P2P cloud. It consists of the following three steps.

(1) create a P2P keyword object

(2) create a registration object associated with the specified cloud,

(3) Register

The following code demonstrates how to register "0. text ", and associate the name with Port 6000 of the Local Machine (usually listen to this port at the same time to respond to requests from resource visitors ).

PeerName pn = new PeerName ("test", PeerNameType. Unsecured );

PeerNameRegistration pnr = new PeerNameRegistration (pn, 6000, Cloud. Available );

Pnr. Start ();

2. To withdraw resources that have been published to the cloud, you only need to call the stop method of the registered object. The Code is as follows.
Pnr. Stop ();

3. Resource Discovery is to search for a specified keyword in the cloud, in the following three steps.
(1) create a name object to be searched.
(2) create a name interpreter object.
(3). retrieve this name object from the specified cloud.
• The following Code demonstrates how to retrieve the name "0. test" from all available clouds. This process returns a maximum of 10 qualified records.
PeerName searchname = new PeerName ("0. test ");

PeerNameResolver resolver = new PeerNameResolver ();

PeerNameRecordCollection results = resolver. Resolve (searchname, Cloud. Available, 10 );

4. After retrieving the corresponding resource name by P2P name, if it is saved in the results collection object, you can obtain the resource corresponding to this name using the following methods.
Foreach (PeerNameRecord record in results)

{

// Obtain the resource location

Foreach (IPEndPoint endpoint in record. EndPointCollection)

{

// The peer usually listens to this IPEndPoint, and initiates a connection with it to communicate with it or interact with it.

}

// Obtain the data corresponding to the Resource

Byte [] remoteresource = record. Data;

}

5. To run the code successfully, the XP system must perform a simple configuration, that is, add "Point-to-Point Service" to the network service in "add and delete windows Components ", if it is a windows 7 or later system, no configuration is required.

Related Article

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.