Jxta--java Peer-to-peer Network Programming Technology (introductory article)

Source: Internet
Author: User

1 . Preface

RecentP2p(Peer-to-peer) has become a hot spot on the internet.Peer-to-peer is an application model of the Internet, meaning that any device on the network (including mainframes,PCs ,PDAs, mobile phones, set-top boxes, and so on) can connect and collaborate equally directly. Compared to the current mainstream Internet application Mode client/server or client/service ,Peer-to-peer has its own distinct characteristics and advantages. (This is where I'm fascinated by it.) Oh...... J)

with peer-to-peer technology, the Internet does not need a large server, which for some industries (especially online games), is very "lucky"! Because peer-to-peer technology is very convenient to achieve you only small money can achieve the desired effect. (Is it a heartbeat?) Oh...... J)

some common peer-to-peer apps: Chat programs, games (especially online games), file sharing, collaborative work, and whiteboards.

Of course,peer-to-peer Networks should also have the following characteristics:

①      p2p system is easy to find and connect each other, Communicate with each other.

② Platform independence: p2p system should be designed to be independent of programming languages such as c,java windows unixtcp/ip bluetooth

③ :peer-to-peer systems can be run on any device with digital processing capabilities.

2 . What's JXTA?

       First of all, jxtap2pp2p

Second,JXTA is a platform for Peer-to-peer application development. At present,JXTA first introduced the JAVA based reference implementation.

It consists of three layers: as shown in Figure 1-1 :

-->

Figure 1-1 Hierarchy of JXTA

The first floor isJxtaCore layer, which contains the core functionality required by the service, includingPeer, peer groups,PeerFoundPeerCommunicationPeerMonitoring and related security primitives; the second tier is the service layer, which provides access to thejxta protocol interface, including for p2p network is not required, but very common features such as find, share , index, code caching, and content caching mechanisms; The third tier is the application layer, which uses services to access jxta Network and jxta provides the function, Including the application jxta service developed a complete p2p applications such as Myjxta,jxta-cad

Here is a brief introduction to some of the concepts of JXTA:

3 . Some concepts of JXTA

Peer (PEER): a virtual point of communication. A user can have multiple Peer, and a single computer or device can have multiple Peer.

Peer Group (peer group): a way of organizing Peer and publishing specific services within a group. Can be created, joined, and exited; In a group, you can update the relationship of a group member.

       Pipe (Pipeline): peerpeer

       advertisement (AD): a xmljxta peerjxtajxtautf-8

Message (message): There are two ways to process messages: ① uses XML format; ② uses binary format.

Rendezvous Peer (Rendezvous point): A Peer that can handle requests from other Peer . You can also delegate a request to another collection point.

       Router Peer peer): a support peerpeer

       Gateway Peer peer): a peer rendezvous Peer The difference is that it is used in peerrendezvous Peer

All right, so many things, even I was a little dizzy. J hehe ... Let's start with an example to familiarize yourself with:

4 . Download and install JXTA

Software Address:jxta.org/">http://www.jxta.org2003-12-15 updated stable version. It offers several platforms, depending on your operating system to select the jxta jxta tool, can be http:// Www.apache.org download. One more note is that you also have to install jdk1.3.1jdk1.4 version.

Here's a little bit about configuration:

Run for the first timeJxtaProgram,JxtaThe configuration tool is automatically displayed. InBasic settingspage, fill in the name you think is cool, show yourPeer Name。 ClickOk。 The next interface enters a secure user name (Secure Username) and Password (Password), and then inExperienced Users onlypage, fill in yourIpAddress and Port,tcp The default port is 9701, The default port is 9700+" button. The meaning of the check box is clear at a glance. Of course you can also click download Relay and Rendezvous Liststcp and http Rendezvous list, and gateway list.

If you have a firewall, be sure to select the use a relay (Required if behind Firewall/nat) check box.

Congratulations, you can feel and experience the JXTA program now. J

5 . Hello JXTA 's simple program

Program Source code:

Hellojxta.java

Import java.io. InputStream;

Import Net. JXTA.peergroup.PeerGroup;

Import Net. JXTA.peergroup.PeerGroupFactory;

Import Net. JXTA.exception.PeerGroupException;

public class Hellojxta {

Public static void main(String args[]) {

System.out.println("Starting JXTA ...");

Hellojxta MyApp = new Hellojxta();

Myapp.startjxta();

System.exit(0);

}

Public void Startjxta() {

Peergroup pg = null;

try {

pg = Peergroupfactory.newnetpeergroup();

Catch (peergroupexception e) {

System.out.println("Fatal Error:group creation Failure");

E.printstacktrace();

system.exit(1);

}

System.out.println("Hello jxta!:)" );

System.out.println("Group name =" +pg.getpeergroupname());

System.out.println("Group ID =" +pg.getpeergroupid(). ToString());

System.out.println("Peer name =" +pg.getpeername());

System.out.println("Peer ID =" +pg.getpeerid(). ToString());

System.out.println("Peer baseclass =" +pg.reftcpprotospecid.getbaseclass());

}

}

Note, however, that this program uses the Jxta.jar file at compile time, so we compile the program:

D:>javac

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.