4904-9 cover 10/12/01 1:10 PM Page Peer-to-Peer Application Development CD-ROM Includes: A professional-quality P2P file-sharing application, plus add-ons Java Software Development Kit Standard Edition version 1.3 for Windows Forte for Java, release 2.0, Community Edition for All Platforms Microsoft DirectX application programming interface SDK, version 8.0a In this unique guide, a crack team of software engineers delivers the programming solutions and source code you need to jump-start a state-of-the-art peer-to-peer application project Using flow charts and line-by-line analysis of a full-scale P2P file-sharing application, they show you how to solve for typical P2P programming challenges — and create your own state-of-the-art P2P application using Java or C#, XML, sockets, threading, ASP, and SQL Server 2000 Peer-to-Peer Application Development is a leading provider of corporate software solutions Based in New Delhi, India, the Dreamtech software team has more than 50 years of combined software engineering experience Peer-to-Peer Application Development Create Tomorrow’s Peer-to-Peer Applications Today Take an In-Depth Look at a Professional-Grade P2P Application • A complete “discovery and look-up server” model P2P application • Listener component that handles requests of incoming peer connections • Server component that maintains the database required for the application • Browser component with a user-friendly interactive interface • Plus modules for streaming, Palm device P2P searching, and a chat client Application tested at Dreamtech Software Research Laboratory Visit www.dreamtechsoftware.com for updates e rc ! M O lines of so + 00 on CD-R u e 9,8 cod Dreamtech Software India, Inc., ISBN 0-7645-4904-9 Intermediate to Advanced Shelving Category Programming *85 -BACGIc $49.99 US $74.99 CANADA £39.99 UK incl VAT lines of so 0+ CD-RO ur 80 e on M d ce ! www.hungryminds.com ,!7IA7G4-fejaef!:p;o;t;T;T Dreamtech Software Team co , Reader Level A line-by-line look inside a professionalgrade P2P file-sharing application Dreamtech Software Team Peer-to-Peer Application Development Peer-to-Peer Application Development Cracking the Code Dreamtech Software Team Best-Selling Books • Digital Downloads • e-Books • Answer Networks • e-Newsletters • Branded Web Sites • e-Learning New York, NY Cleveland, OH Indianapolis, IN Peer-to-Peer Application Development: Cracking the Code Published by Hungry Minds, Inc 909 Third Avenue New York, NY 10022 www.hungryminds.com Copyright © 2002 Hungry Minds, Inc All rights reserved No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher Library of Congress Control Number: 2001095941 ISBN: 0-7645-4904-9 Printed in the United States of America 10 1B/QZ/RR/QR/IN Distributed in the United States by Hungry Minds, Inc Distributed by CDG Books Canada Inc for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty Ltd for Australia and New Zealand; by TransQuest Publishers Pte Ltd for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc for Taiwan; by ICG Muse, Inc for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R Ltda for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc for Micronesia; by Chips Computadoras S.A de C.V for Mexico; by Editorial Norma de Panama S.A for Panama; by American Bookshops for Finland For general information on Hungry Minds’ products and services please contact our Customer Care department within the U.S at 800-762-2974, outside the U.S at 317-572-3993 or fax 317-572-4002 For sales inquiries and reseller information, including discounts, premium and bulk quantity sales, and foreign-language translations, please contact our Customer Care department at 800-434-3422, fax 317-572-4002 or write to Hungry Minds, Inc., Attn: Customer Care Department, 10475 Crosspoint Boulevard, Indianapolis, IN 46256 For information on licensing foreign or domestic rights, please contact our Sub-Rights Customer Care department at 212-8845000 For information on using Hungry Minds’ products and services in the classroom or for ordering examination copies, please contact our Educational Sales department at 800-434-2086 or fax 317-572-4005 For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 317-572-3168 or fax 317-572-4168 For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470 LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES Trademarks: Hungry Minds and the Hungry Minds logo are trademarks or registered trademarks of Hungry Minds, Inc in the United States and other countries and may not be used without written permission Java, Forte, NetBeans and all trademarks and logos based on Java, Forte, and NetBeans are trademarks or registered trademarks of Sun Microsystems, Inc in the U.S and other countries All other trademarks are the property of their respective owners Hungry Minds, Inc., is not associated with any product or vendor mentioned in this book is a trademark of Hungry Minds, Inc Credits Acquisitions Editor Chris Webb Project Coordinator Dale White Project Editor Chandani Thapa Cover Design Anthony Bunyan Technical Editor Dr K.V.K.K Prasad Proofreader Anne Owen Copy Editor C M Jones Indexer Johnna VanHoose Dinse Media Development Specialist Travis Silvers Cover Vault door image used courtesy of Permissions Editor Laura Moss Brown Safe Manufacturing www.BrownSafe.com Media Development Manager Laura Carpenter VanWinkle Dreamtech Software India, Inc., Team dreamtech@mantraonline.com www.dreamtechsoftware.com Dreamtech Software India, Inc., is a leading provider of corporate software solutions Based in New Delhi, India, the company is a successful pioneer of innovative solutions in e-learning technologies Dreamtech’s developers have over 50 years of combined software-engineering experience in areas such as Java, wireless applications, XML, voice-based solutions, NET, COM/COM+ technologies, distributed computing, DirectX, Windows Media technologies, and security solutions About the Authors Lead Author Team Vikas Gupta, Co-founder and President Vikas holds a B.E in electronics, with a postgraduate diploma in sales and marketing and in publishing and printing studies Actively engaged in developing and designing new technologies in wireless applications, e-learning, and other cutting-edge areas, he is also the Managing Director of IDG Books India (P) Ltd Avnish Dass, Co-founder and CEO Avnish is a talented and seasoned programmer who has 15 years of experience in systems and application/database programming Avnish has developed security systems, antivirus programs, wireless and communication technologies, and ERP systems Harpreet Singh Matharu, Sr Software Developer Harpreet holds a B.Tech in computer science Harpreet specializes in COM services and Windows Systems Programming, including Network Programming and Windows Security Systems Ankur Verma, Sr Software Developer Ankur has expertise in technologies such as Windows Media, Direct X (Direct Show), and Windows Shell Programming Services for Windows NT series Ankur also provides the commercial COM/DCOM solutions to Dreamtech Software India, Inc Yashraj Chauhan, Sr Software Developer Yashraj has an advanced diploma in software development from IBM, with over three years of experience in Java, XML, and C++, and is pursuing his Masters in computer science Other Contributors Pooja Aggarwal and Manish Aggarwal, Technical writers They have contributed to developing the contents of this book Gaurav Malhotra, Pankaj Kumar, Manish N Srivastav, A team of programmers of Dreamtech Software India, Inc They contributed to the development of software in this book Acknowledgments We acknowledge the contributions of the following people for their support in making this book possible: John Kilcullen for sharing his dream and providing the vision for making this project a reality Mike Violano and Joe Wikert for believing in us M.V Shastri, Asim Chowdhury, V.K Rajan, Sanjeev Chatterjee, and Priti for their immense help in coordinating various activities throughout this project To our parents and family and beloved country, India, for providing an excellent environment for nurturing and creating world-class IT talent Preface The Internet evolved out of the need to access information from one computer through another or over a network of computers In the beginning, the Internet was a modest network of a few computers allowing access to data through any of its terminals Gradually, the concept opened endless possibilities, and the Internet emerged as a super network — a network of networks — spanning the globe and involving millions of machines over which information could be shared, accessed, or communicated freely by the user Today, with the Internet’s having graduated to the status of a religion that promises to fulfill the needs of everyone, regardless of caste, creed, or color, and having become potent enough to grant anything beseeched, you can find yourself quite lost in its world Consequently, the need for personal attention and smaller subnetworks has risen once again A handful of people got wise to this idea and developed software that allowed users to share data and to communicate with a set of selective people only: friends, relatives, or colleagues This has become among the most sought-after software on the IT market A big user group is benefiting from such software, and many companies are venturing into the concept and capitalizing on it In this scenario, an application made on the concept of Peer-to-Peer (P2P), written in popular languages such as Java and C#, with its foundations for database interaction and communication laid in a platform as ubiquitous as XML and, above all, with open-source code and elaborate code explanations, is what developers of such software ultimately dream of This may sound idealistic, but it is exactly such an application that this book is all about What This Book Covers This book covers the technology of P2P programming This is the first book to cover the entire code behind a Napster-style, file-sharing model It contains unique coverage of Windows Media Technology development for making your P2P application multimedia aware The book is loaded with code, keeping theory to a minimum The applications, for which the source code is given in the CD accompanying this book, are 100 percent tested and working at Dreamtech Software Research Lab The source code provided in the book is based on commercial applications, which have been developed by the software company Each program of the application is explained in detail so that you gain insight into the implementation of the technology in a real-world situation At the end of the book, some add-ons to this application are provided so that you can further explore new developments This book deals with the design, implementation, and coding of the latest form of the client/server model, the P2P model The book serves to equip you with enough know-how on the subject so as to enable you to design a P2P model of your own The book begins with the history of the P2P model and goes on to explain the various types of P2P models, with detailed diagrams to elucidate the subject After equipping you with basic concepts, it goes on to develop, step by step, a full-fledged application, which has the scope of being extended with add-ons This book is not meant for beginners It teaches you the basics of specific technologies only The Cracking the Code series is meant for software developers/programmers who wish to upgrade their skills and understand the secrets behind professional-quality applications This book starts where other tutorial books end It enhances your skills and takes them to the next level as you learn a particular technology A thorough knowledge of the Java or C# programming languages is the prerequisite for benefiting the most from this book Experience in network programming is an added advantage For developing streaming viii Preface applications, knowledge of Visual C++ is a must At least a nodding acquaintance with the XML markup language is desirable, although the book includes a section on XML Instructions for embedding existing chat-client and audio/video components have been included You can craft this application in such a way that you are able to send your files to be printed to any part of the globe Besides Globalized Printing, you can make the application run on wireless models, too The opportunity is open for you to assess your networking skills and to improve them The pivotal feature of the book is that it offers a complete, ready-to-deploy application with source code The purpose of this book is to acquaint programmers with the subject thoroughly so that they are in a position to write their own codes to build P2P applications Detailed explanations of the steps involved in writing your own code to build a P2P application in Java as well as in C # have been furnished Although the topic is highly technical, every effort has been made to make the presentation lucid, interesting, and reader friendly How This Book Is Organized Chapter begins with a discussion of various P2P models, goes on to consider design parameters (including the target audience, the environment, and the possible range this application may be required to serve), and finally covers the implementation aspects of one of the aforementioned models The last chapter is devoted to the add-ons incorporated in the application Chapter explains designing the application you intend to develop Having provided a basic overall view and the technical background of the application, the process of designing the application is taken up in this chapter The chapter begins with a reiteration of design considerations and parameters The sort of communication sought and the means to achieve it by way of this P2P application are detailed The XML design specifications are given in detail, as the interoperability of the P2P application has been achieved by using them The server side is discussed with a description of using the database, the table design, the XML implementation in SQL Server 2000, and so on The client side is described with details of the two modules the client is made up of — the browser and the listener — along with the techniques for handling XML parsing, managing peers, connecting to the server and other peers, and finally searching It is imperative to mention here that the core of this application is discussed in Chapter 2, and it is exceptionally beneficial and mandatory for product designers and programmers aspiring to develop similar applications to peruse this chapter thoroughly Chapter contains every detail of the server in reference to the P2P application Various aspects of using SQL Server 2000, such as table creation with reference to this application and writing queries for retrieving data from tables, have been discussed in this chapter This chapter also walks the reader through XML-related capabilities of SQL Server 2000 Apart from giving you a comprehensive picture of the entire development cycle of the server for this application, this chapter presents a few facts about SQL Server 2000 It elaborates on the complete cycle of database structure tailoring, mounting it, and writing ASPs over it for connected users to be able to interact with it easily A sound command of RDBMS concepts helps you get the maximum benefit from this chapter Chapter introduces you to the task of real cracking of code and illustrates all aspects of high-level programming In the Java version of the P2P application, all codes carry a detailed explanation wherever needed so that you can fully appreciate the code The code explanation starts with a discussion of classes pertaining to operations on XML involved in the application Preface ix After discussing the building blocks of our application, we discuss the application itself This comprises the listener module and the browser module (client) These two interact with each other to give the final shape to this P2P application Apart from covering the entire application development in Java, this chapter describes the use of some of the XML parsers offered by IBM through Java A firm command of Java and a nodding acquaintance with IBM Xerces XML parser is desirable, as this chapter deals primarily with implementation without giving any tutorial of either the language or the parser If you intend to make your application in C#, skip this chapter and proceed to the next chapter Chapter covers the C# version of this P2P application All codes and documentation processes carry a detailed commentary whenever needed so as to enable you to gain a sound understanding of the concept in question The code in this chapter has been written using Microsoft Visual Studio NET (Beta 2) This application constitutes a listener module and a browser module (client), which interact with each other to effect the completion of this P2P application While taking you through the development of the essential modules of this application, this chapter provides you with the opportunity to evaluate your skills in the C# language and to improve them It lets you know how COM components are used in C#, how windows APIs (such as ShellExec()) can be used with interoperable namespaces, and how delegates can be used judiciously in programs A working knowledge of C# and MS XML parser is expected, as this chapter deals primarily with implementation without giving a tutorial of either the language or the parser If you envisage your application in Java, skip this chapter Chapter begins with an elaboration of streaming and goes on to discuss the tools, libraries, and resources required for extending this application to be able to stream audio/video data The chapter concludes by explaining, in steps, the development of a streaming add-on for this P2P application The understanding of Windows Media technologies you gain through this chapter can be directed toward developing or extending applications This knowledge can be used as a bridge to gain access to even better applications of Windows Media technologies and DirectX Because the SDKs involved for developing this add-on are available for VC++ only as of now, you need to know VC++ to understand or develop this add-on This chapter makes use of Windows Media Encoder SDK Familiarity with Windows Media technologies is expected of you Chapter offers you an opportunity to be innovative in extending this so-far-elementary P2P application It provides a deeper insight into the flexibility and the prudence of the design of this application that makes it possible for you to incorporate add-ons to the application even at an advanced stage in its development cycle The implementations of the following add-ons have been described and serve as practical guidelines if you want to explore the possibilities offered by this application: ♦ Chat client ♦ Globalized Printing ♦ P2P wireless search (Java version only) The fully functional chat client incorporated in this application provides you with an understanding of fundamental techniques such as socket programming and introduces you to NET’s powerful resource designer Globalized Printing convinces you how easily a new idea can be incorporated into an application if some care is taken to keep the foundation of the application ubiquitous This notion is further substantiated by the incorporation of the P2P wireless search, which is written in Java and therefore calls for a working knowledge of CLDC (Connected Limited Device Configuration) for a complete appreciation of this extension Index client request handling MultiServer class (Java), 95105 client/server model, P2P–based model and, client-listener connections file_gui class (Java), 134151 clients, chat add-on, 320-321 implementing messaging mechanism, 324-326 message writing notification, 326-327 XML messaging format, 321-324 client-side searches, 11 Close button, 87, 245 CloseSession function, CBroadcastIt class, 287 CLR (Common Language Runtime), 72 columns, SQL select statement, 54 components, 19 connected user lists, retrieving, 36-37 connections, listener design considerations, 32-33 create table keyword, SQL, 53 CreateDocument( ) function, 182 ctxMenuQuit( ) function, 215 D database (P2P application) design issues, 26-27 databases, tables, 52 date and time, obtaining, 301 declarations CBroadcastIt class, 287 CEvents class, 304-311 client class, 129 earch_window class, 134 file_gui class, 149 frmSelection class, 226 frmShare class (C#), 269 GUI objects, 86 MyContentHandler class, 75 search_screen class (Java), 154 ServerCommunication class (C#), 174 SParser class, 115 XMLCreator class (C#), 182 XMLParser class (C#), 198 XMLParserServer class, 75 XMLSTRUCT, 198 definitions, wild_card method, 112 design issues, 18 client, 28 communication with add-ons, 21-22 connections DNS class, 38 HTTP, 37 peers, 37 retrieving connected user lists, 36-37 351 Socket class (Java), 38 TCPClient class (C#), 38 URL calss, 37 data transfer, 19 database, 26-27 downloading procedure flow, 38-40 listener, 29-31 listening for requests, 32-33 multiple connections, 32-33 ServerSocket class (Java), 31 TCPListener class (C#), 32 proxy IP resolution, 19 searching functionality, 35, 40 global searches, 42 local searches, 42 security, 19 server, 25 SQL Server 2000, 25-26 streaming uploads/downloads, 40 uploading procedure flow, 40 XML, implementing in SQL Server 2000, 27-28 XML module, 29 XML parser, 29 MS XML 3.0, 29 Xerces, 29 XML request and response, 24-25 DetermineRequestType( ) function, 182 discovery and lookup server, content searching, 12 querying peers for content, resource sharing, 10 tracing out peers, discovery/lookup/content server, 4-5 content searches, 12 querying peers for content, resource sharing, 10 tracing out peers, Dispose function, 315 Dispose( ) function, 215 DNS class, 38 Download button, 244 DOWNLOAD request type, 105 downloading design considerations, 19 procedure flow, 38, 40 dropped packets, Gnutella, E encoding, audio/video for streaming, 280 environments, design considerations, 18 error messages, audio/video streaming, 280 352 Index ERROR structure, 198 errorinfo element, 183 exceptions, 315 handling parsing XML, 115 XMLParserServer class, 75 Print button, 330 streaming, 315 XML, WriteErrorRequest( ) function, 183 Dispose( ), 215 GetDataFromListener( ), 313 GetDataFromServer, 174 GetDataFromServerUsingProxy( ), 174 GetLocalTime( ), 301 GetRequest( ), 174 GetSelectedItemFromListView( ), 313 IconUpdate( ), 216 InitializeComponent( ), 215 OpenConnection, 330 parse, 115 ReadUserName( ), 215 requests/responses, 115 SaveAndCloseDocuemnt( ), 182 SendDataToListener( ), 313 WriteErrorLog( ), 216 WriteErrorRequest( ), 183 WriteRequest( ), 183 WriteSearchResponse( ), 183 WriteUserName( ), 215 F file_gui class source code, 134-151 files search functionality, design considerations, 35 Share.inin, searching, 86 sharing file_gui class (Java), 134-151 Shareddilog class (Java), 87-94 firewalls application design considerations, 19 Gnutella, flowcharts, asp files, 55, 60-71 folders search functionality, design considerations, 35 sharing, Shareddilog class (Java), 87-94 FOR XML clause, 28 foreign keys, SQL, 54 forms Login source code, 200-217 search interface source code, 274-279 shared resource contents source code, 244-273 sharing resources source code, 217-227 user interface source code, 227-244 Windows Media Player, displaying, 314 frmClient class source code, 227-244 frmLogin class source code, 184, 200-217 frmSearch class source code, 274-279 frmSelection class source code, 217-227 frmShare class source code, 244-273 functions AcceptFunction( ), 216 add-on class, 155 BroadcastStatus, 317 btnQuit Click( ), 215 btnShareFileFolder Click( ), 215 CBroadcastIt class, 287, 288 connecting to servers, 37 CreateDocument( ), 182 ctxMenuQuit( ), 215 DetermineRequestType( ), 182 Dispose, 315 G get_AudioDevices function, CBroadcastIt class, 288 get_AudioMedia function, CBroadcastIt class, 288 get_Port function, CBroadcastIt class, 288 get_Profile function, CBroadcastIt class, 288 get_ProfilesList function, CBroadcastIt class, 288 get_UseScript function, CBroadcastIt class, 288 get_VideoMedia function, CBroadcastIt class, 288 GetDataFromListerner( ) function, 313 GetDataFromServer function, 174 GetDataFromServerUsingProxy( ) function, 174 GetLocalTime( ) function, 301 GetRequest( ) function, 174 GetResponse( ) function, 37 GetResponseStream( ) function, 37 GetSelectedItemFromListView( ) function, 313 global requests, 13 global searches, 42 global variables, XMLParser class, 198 Globalize Printing add-on, 327-332 Gnutella, 6-7 GUI (graphical user interface) buttons Login class, 76 Shareddilog class, 87 components, initializing, 129 Java classes, Shareddilog, 87-94 H Index hardware requirements, 345 Horizons, Gnutella, HTTP servers, connecting to, 37 I I/O limitations, PDAs, 333 IANA port assignment list, Web site, 19 IconUpdate( ) function, 216 iCounter variable, 199 implementation chat client add-on, 320 message writing notification, 326-327 messaging mechanism, 324-326 streaming BroadcastIt component, 288-304 CEvents class, 304-311 browser, 312-315 XML in SQL Server 2000, 27-28 InitializeBroadcaster function, CBroadcastIt class, 288 InitializeComponent( ) function, 215 InputStream class, 40 installing CD-ROM with book, 347 IP addresses proxy servers, 19 retrieving, 175 storing, 86 iTags variable, 199 J-K J2ME programming considerations, 333-334 Java advantages, 72 connecting to server, 37 InputStream class, 40 OutputStream class, 40 P2P application, classes, 72 ServerSocket class, 31 Socket class, 38 source code on CD-ROM (with book), 341-342 XML parser, Xerces, 29 Jdialog class, dialog titles, 94 keys, SQL, 54 L listener, 13 application example, 14 C# source code on CD-ROM with book, 343 chat client add-on, 321 353 Java source code on CD-ROM with book, 341 streaming responding to browser requests, 315317 listener (P2P application) commnication considerations, 22 connection to browser, 23-24 design considerations, 29-31 multiple connections, 32-33 ServerSocket class (Java), 31 TCPListener class (C#), 32 function of, 20 listening for requests, 32-33 operation, 20 source code check_directory class, 105-112 Login class, 76-86 MultiServer class, 95-105 Shareddilog class, 87-94 XMLParserServer class, 73-76 listings add-on.java, 155, 164 check_directory.java, 105, 112 client.java, 119, 128 Declaration of CBroadcastIt class, 283, 287 Declaration of CEvents class, 304, 310 file_gui.java, 135, 149 frmClient, 227, 242 frmLogin, 201, 214 frmSearch, 274, 278 frmSelection, 218, 226 frmShare, 245, 269 Implementation for CBroadcastIt class, 288, 300 login.asp, 57-61 Login.java, 76-85 logout.asp, 62-63, 76 MultiServer.java, 95, 105 search.asp, 67-71 search_screen.java, 152, 154 search_window.java, 130, 134 ServerCommunication Class, 167, 173 Shareddilog.java, 87, 94 Sparser.java, 113-114 userlist.asp, 64-66 userlist.xml, 66-67 XMLCreater Class, 175, 182, 184 XMLParser class, 184, 198 XMLParserServer.java, 73, 75 XMLWriter.java, 116-117 live chat, streaming and, 282 local searches, 42 logging out, 22 354 Index Login ASP, 22 Login button, 76 Login class source code, 76-86 Login form source code, 200-217 login.asp, 55-61 LoginID text box, 200 LOGINXML variable, 198 logout.asp, 61-63 M MakeSession function, CBroadcastIt class, 287 media players, 280 memory design considerations and, 18 limitations, PDAs, 333 utilization techniques, PDAs, 333 MESSAGE structure, 198 messaging, chat client add-on, 324 receiving messasges, 325-326 sending messasges, 324-325 methods declaring, CBraodcastIt class, 287 returnvector class, 75 start_connection, 129 startElement, 76 wild_card, 112 MS XML 3.0 (C# XML parser), 29 MSXML2.IXMLDOMDOCUMENT variable, 199 MSXML2.IXMLDOMELEMENT variable, 199 MSXML2.IXMLDOMNode variable, 199 MSXML2.IXMLDOMNodeList variable, 199 MSXML2.IXMLDOMNodeMap variable, 199 multimedia streaming, 280 multiple connections, design considerations, 32-33 MultiServer class source code, 95-105 N Napster, 5-6 networks design considerations and, 18 printing, 327-328 NetworkStream class, 40 O objects Dispose functions, 315 GUI, declaring, 86 Open button, 227 OpenConnection function, 330 operation flow of P2P application, 43-51 OutputStream class, 40 P P2P history, 1-2 P2P applications Gnutella, 6-7 Napster, 5-6 P2P models discovery and lookup server, discovery/lookup/content server, 4-5 Pure P2P, simple discovery server, 3-4 p2p_lng tag, 67 P2PServer folder contents (CD-ROM with book), 344 P2PwithAddons folder (CD-ROM with book), 343 packages CBroadcastIt class, 300 client (P2P application), 115 listener (P2P application), 75 P2P application, C# implementation, 174 packets, Gnutella, parse function, 115 parsing XML files, Sparser class (Java), 112-115 PDAs (Personal Desktop Assistants) J2ME programming considerations, 333 limitations, 333 search application, 334-340 user interface, 334 peer application class, 334 Peer Table structure, 26 peers connecting to, 37 querying for required content, tracing out, performance, Java compared to C#, 72 ports firewalls, design considerations, 19 Gnutella, ranges, 19 PrepareToEncode function, CBroadcastIt class, 288 primary keys, SQL, 54 Print button adding, 328 coding, 328-333 PRINT request type, 328 printing, networks, 327-332 processor limitations, PDAs, 333 programming C# disadvantages, 72 constraints, PDAs, 333 Index J2ME considerations, PDAs, 333 Print button, 328-330 listener, 331-333 search application, PDAs, 334-340 user interface, PDAs, 334 proxy servers, IP addresses, 19 Pure P2P content searches, 11 querying peers for content, resource sharing, 10 tracing out peers, Pure P2P model, push requests, Gnutella, put_AudioMedia function, CBroadcastIt class, 288 put_Port function, CBroadcastIt class, 288 put_Profile function, CBroadcastIt class, 288 put_UseScript function, CBroadcastIt class, 288 put_VideoMedia function, CBroadcastIt class, 288 Q queries required content, XML, retuning instead of rowsets, 28 Quit button, 200, 227 R radio buttons, Shareddilog class, 87 radio stations, maintaining with streaming capability, 282 ReadUserName( ) function, 215 Refresh button, 227 Remember my Login ID checkbox, 76 request types CHAT, 321 client requests and, 105 PRINT, 328 STREAMING, 283 Request XMLs, 24 requestFString( ) function, 115 requests streaming, creating, 313 XMLWriter class, 115-118 resource sharing, 10 responding to requests, XMLWriter class, 115-118 Response XMLs, 24 responseFString( ) function, 116 returnRequest( ) function, 115 returnResponse( ) function, 116 returnvector method, 75 root searches, 13 355 S SaveAndCloseDocument( ) function, 182 scalability, design considerations, 18 search application, PDAs, 334-340 Search button, 227, 244 search interface form source code, 274-279 SEARCH request type, 105 search.asp, 67-71 search_request( ) function, 155 search_screen class source code, 151-155 search_window class source code, 130-134 searches design considerations, 35, 40 global searches, 42 local searches, 42 global requests, 13 MultiServer class (Java), 105-112 root searches, 13 search_screen class (Java), 151-155 search_window class (Java), 130-134 server-side, 11 Share.inin file, 86 shared resources, 10-12 searchfiles class, 337 security, design considerations, 19 SELECT statement, FOR XML clause, 28 select statement, SQL, 54 SendDataToListerner( ) function, 313 SendScript function, CBroadcastIt class, 287 SendURL function, CBroadcastIt class, 287 Servents, Gnutella, server application example, 13 listener relationship, application example, 14-15 server (P2P application) design considerations, 25-26 function of, 20 ServerCommunication class source code, 167-175 servers connected user lists, retrieving, 36-37 connecting with HTTP, 37 connecting with URL calss, 37 discovery and lookup, discovery/lookup/content, 4-5 proxy, IP addresses, 19 simple discovery server, 3-4 serversearch class, 336 SERVERSEARCH structure, 198 SERVERSEARCHXML variable, 199 server-side searches, 11 ServerSocket class (Java), 31 356 Index Share Files/Folder button, 200 Share Table structure, 27 Share.ini file, searching, 86 Shared Files button, 76 shared resource contents form source code, 244-273 shared resources, searching for, 10-12 Shareddilog class source code, 87-94 ShareFile button, 87 ShareFolder button, 87 Shareit button, 87 sharing files, file_gui class (Java), 134-151 sharing files and folders, Shareddilog class (Java), 87-94 sharing resources, 10 sharing resources form, source code, 217-227 showfiles class, 336 SHOWFILES request type, 105 SHOWFILES structure, 198 simple discovery server, 3-4 content searches, 11 querying peers for content, resource sharing, 10 tracing out peers, Socket class, 38 software requirements, 345-347 sorting( ) function, 155 Source Collection Groups, audio/vodeo streaming, 280 Source Groups, audio/vodeo streaming, 280 SParser class, 72, 112-115 SQL keys, 54 queries, returning XML instead of rowsets, 28 select statement, 54 SQL Server create table keyword, 53 tables, creating, 52-54 SQL Server 2000, 52 features, 25-26 XML implementation, 27-28 start_connection method, 129 start_connection( ) function, 155 startElement method, 76 Status function, CBroadcastIt class, 287 Stream button (browser), 312-313 streaming, 280 application, running, 317-319 attributes, assigning, 280 BroadcastIt component, 283-288 design considerations, 283-311 exceptions, 315 implementation BroadcastIt component, 288-304 BroadcastIt component's CEvents class, 304311 implementing, browser, 312-315 listeners, responding to browser requests, 315317 media players, 280 memory, clearing, 315 process of, 280 requests, creating, 313 uploads/downloads, 40 uses for, 282-283 Windows Media Encoder SDK benefits, 282 required tools, 282 STREAMING request type, 283 StreamIt class, 315 string types, 118 system data and time, obtaining, 301 system requirements hardware, 345 software, 345-347 T tables, SQL Server, 52-54 TCPClient class, 38 TCPListener class (C#), 32 TextField button, 87 threads, creating for peers, 32 time and date, 301 tracing out peers, troubleshooting CD-ROM with book, 347-348 U Upload button, 244 UPLOAD request type, 105 uploading, design considerations, 19 uploading procedure flow, 40 URL class servers, connecting to, 37 user interface, PDAs, 334 user interface form source code, 227-244 USERID parameter, login.asp, 55 userlist screen class, 335 USERLIST structure, 198 userlist.asp, 63-66 userlist.xml, 66-67 USERLISTXML variable, 198 V Index variables declaring, CBraodcastIt class, 287 global, XMLParser class, 198 Vector class, 72 video streaming, 280 ViewFiles button, 227 Visual C++, Windows Media Encoder SDK and, 282 W Web sites C# P2P application executables, 167 IANA port assignment list, 19 software requirements for CD-ROM with book, 345-347 Windows Media Player, 280 wild_card method, 112 windows creation, chat client add-on, 321 Windows Media Encoder, 280 Windows Media Encoder SDK benefits, 282 required tools, 282 Windows Media Player download site, 280 form for displaying, 314 WorkingWithXML folder (on CD-ROM with book), 343 WriteErrorLog( ) function, 216 WriteErrorResponse( ) function, 183 WriteRequest( ) function, 183 WriteSearchResponse( ) function, 183 WriteUserName( ) function, 215 X-Y-Z Xerces (Java XML parser), 29 XML (eXtensible Markup Language) browser to listener communications, 23-24 CreateDocument( ) function, 182 importance in P2P application, 20 messages, sending, 324-325 messaging format, chat client add-on, 321-324 printing, Globalize Printing add-on, 328 queries:, 28 request and response design specifications, 24-25 userlist.xml file, 66-67 XML module design considerations, 29 parsers, 29 MS XML 3.0, 29 Xerces, 29 XMLCreater class source code, 175-184 XMLParser class source code, 184-200 XMLParserServer class source code, 73-76 XMLSTRUCT type, 198 xmlwriter class, 72 XMLWriter class source code, 115-118 357 Hungry Minds, Inc End-User License Agreement READ THIS You should carefully read these terms and conditions before opening the software packet(s) included with this book (“Book”) This is a license agreement (“Agreement”) between you and Hungry Minds, Inc (“HMI”) By opening the accompanying software packet(s), you acknowledge that you have read and accept the following terms and conditions If you not agree and not want to be bound by such terms and conditions, promptly return the Book and the unopened software packet(s) to the place you obtained them for a full refund License Grant HMI grants to you (either an individual or entity) a nonexclusive license to use one copy of the enclosed software program(s) (collectively, the “Software”) solely for your own personal and non-commercial purposes on a single computer (whether a standard computer or a workstation component of a multi-user network) The Software is in use on a computer when it is loaded into temporary memory (RAM) or installed into permanent memory (hard disk, CD-ROM, or other storage device) HMI reserves all rights not expressly granted herein Ownership HMI is the owner of all right, title, and interest, including copyright, in and to the compilation of the Software recorded on the disk(s) or CD-ROM (“Software Media”) Copyright to the individual programs recorded on the Software Media is owned by the author or other authorized copyright owner of each program Ownership of the Software and all proprietary rights relating thereto remain with HMI and its licensers Restrictions on Use and Transfer (a) You may only (i) make one copy of the Software for backup or archival purposes, or (ii) transfer the Software to a single hard disk, provided that you keep the original for backup or archival purposes You may not (i) rent or lease the Software, (ii) copy or reproduce the Software through a LAN or other network system or through any computer subscriber system or bulletin-board system, or (iii) modify, adapt, or create derivative works based on the Software (b) You may not reverse engineer, decompile, or disassemble the Software You may transfer the Software and user documentation on a permanent basis, provided that the transferee agrees to accept the terms and conditions of this Agreement and you retain no copies If the Software is an update or has been updated, any transfer must include the most recent update and all prior versions Restrictions on Use of Individual Programs You must follow the individual requirements and restrictions detailed for each individual program in the What’s on the CD-ROM appendix of this Book These limitations are also contained in the individual license agreements recorded on the Software Media These limitations may include a requirement that after using the program for a specified period of time, the user must pay a registration fee or discontinue use By opening the Software packet(s), you will be agreeing to abide by the licenses and restrictions for these individual programs that are detailed in the What’s on the CD-ROM appendix and on the Software Media None of the material on this Software Media or listed in this Book may ever be redistributed, in original or modified form, for commercial purposes Limited Warranty (a) HMI warrants that the Software and Software Media are free from defects in materials and workmanship under normal use for a period of sixty (60) days from the date of purchase of this Book If HMI receives notification within the warranty period of defects in materials or workmanship, HMI will replace the defective Software Media (b) HMI AND THE AUTHOR OF THE BOOK DISCLAIM ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE, THE PROGRAMS, THE SOURCE CODE CONTAINED THEREIN, AND/OR THE TECHNIQUES DESCRIBED IN THIS BOOK HMI DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION OF THE SOFTWARE WILL BE ERROR FREE (c) This limited warranty gives you specific legal rights, and you may have other rights that vary from jurisdiction to jurisdiction Remedies (a) HMI’s entire liability and your exclusive remedy for defects in materials and workmanship shall be limited to replacement of the Software Media, which may be returned to HMI with a copy of your receipt at the following address: Software Media Fulfillment Department, Attn.: Peer-to-Peer Application Development: Cracking the Code, Hungry Minds, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, or call 1-800-762-2974 Please allow four to six weeks for delivery This Limited Warranty is void if failure of the Software Media has resulted from accident, abuse, or misapplication Any replacement Software Media will be warranted for the remainder of the original warranty period or thirty (30) days, whichever is longer (b) In no event shall HMI or the author be liable for any damages whatsoever (including without limitation damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising from the use of or inability to use the Book or the Software, even if HMI has been advised of the possibility of such damages (c) Because some jurisdictions not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation or exclusion may not apply to you U.S Government Restricted Rights Use, duplication, or disclosure of the Software for or on behalf of the United States of America, its agencies and/or instrumentalities (the "U.S Government") is subject to restrictions as stated in paragraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause of DFARS 252.227-7013, or subparagraphs (c) (1) and (2) of the Commercial Computer Software - Restricted Rights clause at FAR 52.227-19, and in similar clauses in the NASA FAR supplement, as applicable General This Agreement constitutes the entire understanding of the parties and revokes and supersedes all prior agreements, oral or written, between them and may not be modified or amended except in a writing signed by both parties hereto that specifically refers to this Agreement This Agreement shall take precedence over any other documents that may be in conflict herewith If any one or more provisions contained in this Agreement are held by any court or tribunal to be invalid, illegal, or otherwise unenforceable, each and every other provision shall remain in full force and effect Sun Microsystems, Inc Binary Code License Agreement READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY "AGREEMENT") CAREFULLY BEFORE OPENING THE SOFTWARE MEDIA PACKAGE BY OPENING THE SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS AGREEMENT IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY, INDICATE YOUR ACCEPTANCE OF THESE TERMS BY SELECTING THE "ACCEPT" BUTTON AT THE END OF THIS AGREEMENT IF YOU DO NOT AGREE TO ALL THESE TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUND OR, IF THE SOFTWARE IS ACCESSED ELECTRONICALLY, SELECT THE "DECLINE" BUTTON AT THE END OF THIS AGREEMENT LICENSE TO USE Sun grants you a non-exclusive and non-transferable license for the internal use only of the accompanying software and documentation and any error corrections provided by Sun (collectively "Software"), by the number of users and the class of computer hardware for which the corresponding fee has been paid RESTRICTIONS Software is confidential and copyrighted Title to Software and all associated intellectual property rights is retained by Sun and/or its licensors Except as specifically authorized in any Supplemental License Terms, you may not make copies of Software, other than a single copy of Software for archival purposes Unless enforcement is prohibited by applicable law, you may not modify, decompile, or reverse engineer Software You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility Sun disclaims any express or implied warranty of fitness for such uses No right, title or interest in or to any trademark, service mark, logo or trade name of Sun or its licensors is granted under this Agreement LIMITED WARRANTY Sun warrants to you that for a period of ninety (90) days from the date of purchase, as evidenced by a copy of the receipt, the media on which Software is furnished (if any) will be free of defects in materials and workmanship under normal use Except for the foregoing, Software is provided "AS IS" Your exclusive remedy and Sun's entire liability under this limited warranty will be at Sun's option to replace Software media or refund the fee paid for Software DISCLAIMER OF WARRANTY UNLESS SPECIFIED IN THIS AGREEMENT, ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID LIMITATION OF LIABILITY TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES In no event will Sun's liability to you, whether in contract, tort (including negligence), or otherwise, exceed the amount paid by you for Software under this Agreement The foregoing limitations will apply even if the above stated warranty fails of its essential purpose Termination This Agreement is effective until terminated You may terminate this Agreement at any time by destroying all copies of Software This Agreement will terminate immediately without notice from Sun if you fail to comply with any provision of this Agreement Upon Termination, you must destroy all copies of Software Export Regulations All Software and technical data delivered under this Agreement are subject to US export control laws and may be subject to export or import regulations in other countries You agree to comply strictly with all such laws and regulations and acknowledge that you have the responsibility to obtain such licenses to export, re-export, or import as may be required after delivery to you U.S Government Restricted Rights If Software is being acquired by or on behalf of the U.S Government or by a U.S Government prime contractor or subcontractor (at any tier), then the Government's rights in Software and accompanying documentation will be only as set forth in this Agreement; this is in accordance with 48 CFR 227.7201 through 227.7202-4 (for Department of Defense (DOD) acquisitions) and with 48 CFR 2.101 and 12.212 (for non-DOD acquisitions) Governing Law Any action related to this Agreement will be governed by California law and controlling U.S federal law No choice of law rules of any jurisdiction will apply 10 Severability If any provision of this Agreement is held to be unenforceable, this Agreement will remain in effect with the provision omitted, unless omission would frustrate the intent of the parties, in which case this Agreement will immediately terminate 11 Integration This Agreement is the entire agreement between you and Sun relating to its subject matter It supersedes all prior or contemporaneous oral or written communications, proposals, representations and warranties and prevails over any conflicting or additional terms of any quote, order, acknowledgment, or other communication between the parties relating to its subject matter during the term of this Agreement No modification of this Agreement will be binding, unless in writing and signed by an authorized representative of each party Java(TM) Software Development Kit (J2SDK), Standard Edition, Version 1.3 SUPPLEMENTAL LICENSE TERMS These supplemental license terms ("Supplemental Terms") add to or modify the terms of the Binary Code License Agreement (collectively, the "Agreement") Capitalized terms not defined in these Supplemental Terms shall have the same meanings ascribed to them in the Agreement These Supplemental Terms shall supersede any inconsistent or conflicting terms in the Agreement, or in any license contained within the Software Software Internal Use and Development License Grant Subject to the terms and conditions of this Agreement, including, but not limited to Section (Java(TM) Technology Restrictions) of these Supplemental Terms, Sun grants you a non-exclusive, non-transferable, limited license to reproduce internally and use internally the binary form of the Software complete and unmodified for the sole purpose of designing, developing and testing your Java applets and applications intended to run on the Java platform ("Programs") License to Distribute Software Subject to the terms and conditions of this Agreement, including, but not limited to Section (Java (TM) Technology Restrictions) of these Supplemental Terms, Sun grants you a non-exclusive, non-transferable, limited license to reproduce and distribute the Software in binary code form only, provided that (i) you distribute the Software complete and unmodified and only bundled as part of, and for the sole purpose of running, your Programs, (ii) the Programs add significant and primary functionality to the Software, (iii) you not distribute additional software intended to replace any component(s) of the Software, (iv) you not remove or alter any proprietary legends or notices contained in the Software, (v) you only distribute the Software subject to a license agreement that protects Sun's interests consistent with the terms contained in this Agreement, and (vi) you agree to defend and indemnify Sun and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software License to Distribute Redistributables Subject to the terms and conditions of this Agreement, including but not limited to Section (Java Technology Restrictions) of these Supplemental Terms, Sun grants you a non-exclusive, non-transferable, limited license to reproduce and distribute the binary form of those files specifically identified as redistributable in the Software "README" file ("Redistributables") provided that: (i) you distribute the Redistributables complete and unmodified (unless otherwise specified in the applicable README file), and only bundled as part of Programs, (ii) you not distribute additional software intended to supersede any component(s) of the Redistributables, (iii) you not remove or alter any proprietary legends or notices contained in or on the Redistributables, (iv) you only distribute the Redistributables pursuant to a license agreement that protects Sun's interests consistent with the terms contained in the Agreement, and (v) you agree to defend and indemnify Sun and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software Java Technology Restrictions You may not modify the Java Platform Interface ("JPI", identified as classes contained within the "java" package or any subpackages of the "java" package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI In the event that you create an additional class and associated API(s) which (i) extends the functionality of the Java platform, and (ii) is exposed to third party software developers for the purpose of developing additional software which invokes such additional API, you must promptly publish broadly an accurate specification for such API for free use by all developers You may not create, or authorize your licensees to create, additional classes, interfaces, or subpackages that are in any way identified as "java", "javax", "sun" or similar convention as specified by Sun in any naming convention designation Trademarks and Logos You acknowledge and agree as between you and Sun that Sun owns the SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANET trademarks and all SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANETrelated trademarks, service marks, logos and other brand designations ("Sun Marks"), and you agree to comply with the Sun Trademark and Logo Usage Requirements currently located at http://www.sun.com/policies/trademarks Any use you make of the Sun Marks inures to Sun's benefit Source Code Software may contain source code that is provided solely for reference purposes pursuant to the terms of this Agreement Source code may not be redistributed unless expressly provided for in this Agreement Termination for Infringement Either party may terminate this Agreement immediately should any Software become, or in either party's opinion be likely to become, the subject of a claim of infringement of any intellectual property right For inquiries please contact: Sun Microsystems, Inc 901 San Antonio Road, Palo Alto, California 94303 License Agreement: Forte for Java, release 2.0 Community Edition for All Platforms To obtain Forte for Java, release 2.0, Community Edition for All Platforms, you must agree to the software license below Sun Microsystems Inc., Binary Code License Agreement READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY "AGREEMENT") CAREFULLY BEFORE OPENING THE SOFTWARE MEDIA PACKAGE BY OPENING THE SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS AGREEMENT IF YOU ARE ACCESSING THE SOFTWARE ELECTRONICALLY, INDICATE YOUR ACCEPTANCE OF THESE TERMS BY SELECTING THE "ACCEPT" BUTTON AT THE END OF THIS AGREEMENT IF YOU DO NOT AGREE TO ALL THESE TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUND OR, IF THE SOFTWARE IS ACCESSED ELECTRONICALLY, SELECT THE "DECLINE" BUTTON AT THE END OF THIS AGREEMENT LICENSE TO USE Sun grants you a non-exclusive and non-transferable license for the internal use only of the accompanying software and documentation and any error corrections provided by Sun (collectively "Software"), by the number of users and the class of computer hardware for which the corresponding fee has been paid RESTRICTIONS Software is confidential and copyrighted Title to Software and all associated intellectual property rights is retained by Sun and/or its licensors Except as specifically authorized in any Supplemental License Terms, you may not make copies of Software, other than a single copy of Software for archival purposes Unless enforcement is prohibited by applicable law, you may not modify, decompile, or reverse engineer Software You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility Sun disclaims any express or implied warranty of fitness for such uses No right, title or interest in or to any trademark, service mark, logo or trade name of Sun or its licensors is granted under this Agreement LIMITED WARRANTY Sun warrants to you that for a period of ninety (90) days from the date of purchase, as evidenced by a copy of the receipt, the media on which Software is furnished (if any) will be free of defects in materials and workmanship under normal use Except for the foregoing, Software is provided "AS IS" Your exclusive remedy and Sun's entire liability under this limited warranty will be at Sun's option to replace Software media or refund the fee paid for Software DISCLAIMER OF WARRANTY UNLESS SPECIFIED IN THIS AGREEMENT, ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE LEGALLY INVALID LIMITATION OF LIABILITY TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES In no event will Sun's liability to you, whether in contract, tort (including negligence), or otherwise, exceed the amount paid by you for Software under this Agreement The foregoing limitations will apply even if the above stated warranty fails of its essential purpose Termination This Agreement is effective until terminated You may terminate this Agreement at any time by destroying all copies of Software This Agreement will terminate immediately without notice from Sun if you fail to comply with any provision of this Agreement Upon Termination, you must destroy all copies of Software Export Regulations All Software and technical data delivered under this Agreement are subject to US export control laws and may be subject to export or import regulations in other countries You agree to comply strictly with all such laws and regulations and acknowledge that you have the responsibility to obtain such licenses to export, re-export, or import as may be required after delivery to you U.S Government Restricted Rights If Software is being acquired by or on behalf of the U.S Government or by a U.S Government prime contractor or subcontractor (at any tier), then the Government's rights in Software and accompanying documentation will be only as set forth in this Agreement; this is in accordance with 48 CFR 227.7201 through 227.7202-4 (for Department of Defense (DOD) acquisitions) and with 48 CFR 2.101 and 12.212 (for non-DOD acquisitions) Governing Law Any action related to this Agreement will be governed by California law and controlling U.S federal law No choice of law rules of any jurisdiction will apply 10 Severability If any provision of this Agreement is held to be unenforceable, this Agreement will remain in effect with the provision omitted, unless omission would frustrate the intent of the parties, in which case this Agreement will immediately terminate 11 Integration This Agreement is the entire agreement between you and Sun relating to its subject matter It supersedes all prior or contemporaneous oral or written communications, proposals, representations and warranties and prevails over any conflicting or additional terms of any quote, order, acknowledgment, or other communication between the parties relating to its subject matter during the term of this Agreement No modification of this Agreement will be binding, unless in writing and signed by an authorized representative of each party JAVA™ DEVELOPMENT TOOLS FORTE™ FOR JAVA™, RELEASE 2.0, COMMUNITY EDITION SUPPLEMENTAL LICENSE TERMS These supplemental license terms ("Supplemental Terms") add to or modify the terms of the Binary Code License Agreement (collectively, the "Agreement") Capitalized terms not defined in these Supplemental Terms shall have the same meanings ascribed to them in the Agreement These Supplemental Terms shall supersede any inconsistent or conflicting terms in the Agreement, or in any license contained within the Software Software Internal Use and Development License Grant Subject to the terms and conditions of this Agreement, including, but not limited to Section (Java(TM) Technology Restrictions) of these Supplemental Terms, Sun grants you a non-exclusive, non-transferable, limited license to reproduce internally and use internally the binary form of the Software complete and unmodified for the sole purpose of designing, developing and testing your [Java applets and] applications intended to run on the Java platform ("Programs") License to Distribute Redistributables In addition to the license granted in Section (Redistributables Internal Use and Development License Grant) of these Supplemental Terms, subject to the terms and conditions of this Agreement, including, but not limited to Section (Java Technology Restrictions) of these Supplemental Terms, Sun grants you a non-exclusive, nontransferable, limited license to reproduce and distribute those files specifically identified as redistributable in the Software “README” file (“Redistributables”) provided that: (i) you distribute the Redistributables complete and unmodified (unless otherwise specified in the applicable README file), and only bundled as part of your Programs, (ii) you not distribute additional software intended to supercede any component(s) of the Redistributables, (iii) you not remove or alter any proprietary legends or notices contained in or on the Redistributables, (iv) for a particular version of the Java platform, any executable output generated by a compiler that is contained in the Software must (a) only be compiled from source code that conforms to the corresponding version of the OEM Java Language Specification; (b) be in the class file format defined by the corresponding version of the OEM Java Virtual Machine Specification; and (c) execute properly on a reference runtime, as specified by Sun, associated with such version of the Java platform, (v) you only distribute the Redistributables pursuant to a license agreement that protects Sun's interests consistent with the terms contained in the Agreement, and (vi) you agree to defend and indemnify Sun and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software Java Technology Restrictions You may not modify the Java Platform Interface ("JPI", identified as classes contained within the "java" package or any subpackages of the "java" package), by creating additional classes within the JPI or otherwise causing the addition to or modification of the classes in the JPI In the event that you create an additional class and associated API(s) which (i) extends the functionality of the Java platform, and (ii) is exposed to third party software developers for the purpose of developing additional software which invokes such additional API, you must promptly publish broadly an accurate specification for such API for free use by all developers You may not create, or authorize your licensees to create, additional classes, interfaces, or subpackages that are in any way identified as "java", "javax", "sun" or similar convention as specified by Sun in any naming convention designation Java Runtime Availability Refer to the appropriate version of the Java Runtime Environment binary code license (currently located at http://www.java.sun.com/jdk/index.html) for the availability of runtime code which may be distributed with Java applets and applications Trademarks and Logos You acknowledge and agree as between you and Sun that Sun owns the SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANET trademarks and all SUN, SOLARIS, JAVA, JINI, FORTE, STAROFFICE, STARPORTAL and iPLANETrelated trademarks, service marks, logos and other brand designations ("Sun Marks"), and you agree to comply with the Sun Trademark and Logo Usage Requirements currently located at http://www.sun.com/policies/trademarks Any use you make of the Sun Marks inures to Sun's benefit Source Code Software may contain source code that is provided solely for reference purposes pursuant to the terms of this Agreement Source code may not be redistributed unless expressly provided for in this Agreement Termination for Infringement Either party may terminate this Agreement immediately should any Software become, or in either party's opinion be likely to become, the subject of a claim of infringement of any intellectual property right For inquiries please contact: Sun Microsystems, Inc 901 San Antonio Road, Palo Alto, California 94303 ... queries for the content the requesting peer seeks The requesting peer in this case passes its query to the server, not to individual peer The server processes the query to locate the peer that... directories of the MP3 music files stored on the machines of users These directories are updated every time you log onto or off of the Napster server 6 Chapter 1: An Introduction to the Peer- To -Peer. .. in the pure P2P model: A peer passes its request for content to another peer, the latter being referred to as the host peer If the host peer contains the required information and it is within the