The Gnutella file-sharing network and Java

Use the JTella API to easily develop applications that access Gnutella

Page 2 of 2
    if ( 2 == connectionCount)
    {
      System.out.println("Sending search request");
      // Search for elvis, and one sure to get results
      SearchSession search1 = conn.createSearchSession(new TestReceiver());
      search1.search("elvis", 100, 0);
      SearchSession search2 = conn.createSearchSession(new TestReceiver());
      search2.search(".mp3", 100, 0);
    }

As before, the NetworkConnection is used to create a SearchSession, which can be used to send a search request over the network. Also as before, a callback method is used to return the results. The definition of the search callback is shown below:

public void receiveSearchReply(SearchReplyMessage searchReply)

When JTella calls this method, it indicates that a servant on the network is responding positively to a search query sent by the JTella servant. The response will contain information enabling the use of HTTP to download the file, as well as the names and number of files matching your search query.

Conclusion

Peer-to-peer computing's time has come. When it is used in the fashion that Gnutella employs, the Internet becomes a much larger communications space. Instead of a group of servers you can access for files and services, the Internet can let you reach into the computers of other connected users. As the technology evolves, the speed and scale of the file-sharing system should start to realize its tremendous potential.

Another obvious use for peer-to-peer networking is general searching on the Internet. Consider the current state-of-the-art procedure for searching on the Internet: You submit a Website to a search engine to include in its database. At some point, the search engine reads your Webpage and indexes it based on the keywords it finds in your HTML page. The information in the search database will always be out of date, since the Webpage is not reindexed each time it is updated. And if your site is mostly dynamic and stored in a database, the Web-crawling software may not find it.

Now suppose the search engine was using a peer-to-peer network: Whenever a user submitted a query, the search engine would submit it to the peer-to-peer network and wait for the results. The problems of finding dynamic pages would be solved -- and the search engine would return current results, since the peer-to-peer search occurred at the time of the user request.

Happy file sharing!

Ken McCrary is a Sun-certified Java developer living in Research Triangle Park, N.C. He has worked on Java projects ranging from Web applets to embedded Java systems. You can visit his Website at http://www.KenMcCrary.com.

Learn more about this topic

| 1 2 Page 2