Author Topic: P2P Sockets (reimplementation of standard Java sockets)  (Read 7479 times)

0 Members and 1 Guest are viewing this topic.

Offline Nemo

  • Global Moderator
  • Elite
  • *****
  • Posts: 1303
  • Karma: +27/-0
    • View Profile
P2P Sockets (reimplementation of standard Java sockets)
« on: June 08, 2004, 07:37:27 AM »
source: http://p2psockets.jxta.org/
summary: A reimplementation of standard Java sockets on top of JXTA
Quote

What is P2P Sockets?
P2P Sockets makes it easy to write peer-to-peer applications based on JXTA. P2P Sockets allows programmers to gain much of the power of JXTA, such as NAT and firewall traversal, without being exposed to its complexity. It does this through ports of popular software projects, such as a web server and web services stack, to work on the JXTA peer-to-peer network. This includes a web server (Jetty) that can receive requests and serve content over the peer-to-peer network; a servlet and JSP engine (Jetty and Jasper) that allows existing servlets and JSPs to serve P2P clients; an XML-RPC client and server (Apache XML-RPC) for accessing and exposing P2P XML-RPC endpoints; an HTTP/1.1 client (Apache Commons HTTP-Client) that can access P2P web servers; a gateway (Smart Cache) to make it possible for existing browsers to access P2P web sites; and a WikiWiki (JSPWiki) that can be used to host WikiWikis on your local machine that other peers can access and edit through the P2P network. P2P Sockets also introduces implementations of java.net.Socket and java.net.ServerSocket that can work on the JXTA network as well as a simple, light-weight, distributed, human-friendly, and non-secure DNS system. For example, to have a peer expose a simple service that can be reached by other peers, you would use the following code:

// create a service with the name "www.nike.laborpolicy" on virtual port 100
java.net.ServerSocket server = new P2PServerSocket("www.nike.laborpolicy", 100); // port 100
// wait for a client to connect
java.net.Socket client = server.accept();
// client accepted; now communicate
InputStream in = client.getInputStream();
OutputStream out = client.getOutputStream();
// do application specific work now

The client side is just as simple:

// connect to a peer offering the service at "www.nike.laborpolicy" on virtual port 100
java.net.Socket socket = new P2PSocket("www.nike.laborpolicy", 100);
// now start communicating
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();

Peers can now host and consume services even if they are normally unreachable, such as if they are behind NAT or firewalls, and can publish services to P2P Socket's lightweight distributed domain name system without having to configure or deploy customized DNS servers.


A comment: Only TCP Sockets are implemented yet.

Greetings,
Nemo.