基于JAVA 的P2P


基于JAVA 的P2P 软件,需JDK 1.3
资源截图
代码片段和文件信息
import java.net.*;
import java.io.*;
import java.util.*;
/* This class file is a mutipurpose class file it contains many functions which are used 
   over a series of classes in the project...
 */

class add_on  
{
Socket file_socket;
String viewfiles[][];
static Vector filenames ; // A vector to maintain the user list (static) 


add_on() // Constructor...
{

}
/*  This function is used to adjust the length of the byte array and to make it 
equal to 1024 byte this is done in order to make the size of the request 
equal to the request accepted by the C# listener... 

In the function appropriatelength two parameters are passed 
1. Byte array...
2. Length of byte array...

The rest of the bytes (1024 - length) are first converted into character and 
then made into  char ‘13‘ and then converted into bytes again..

*/

public byte [] appropriatelength(byte[] file_bytes int file_size)
{
int count = 0;
byte b[] = new byte[1024];
int remaining = 1024-file_size;

for (int i = 0;i {
b[i] = file_bytes[i];
}

char a[] = new char[remaining];

for (int i = 0;i {
a[i] = 13;
}

String tempw = new String(a);
byte d[] = tempw.getBytes();

for (int i=file_size;i<1024 ;i++ )
{
b[i] = d[(i-file_size)];
}

return (b);
} // End Appropriate length.....

/* This function is used to issue the search request... 
It takes 4 parameters...
1. Directory information...
2. Search Criteria.. 
3. Ip_address of the listener...
4. Flag_information of the directory on which search is made...

*/


public void search_request(String directory String condition String ip_address String flag_info)
{

try
{
InetAddress inet = InetAddress.getByName(ip_address);
file_socket = new Socket(inet7070); // Create a client_socket on the 
// Listener‘s machine at port 7070. 

// Get The output as well as the input Streams on that socket... 
BufferedOutputStream out = new BufferedOutputStream(file_socket.getOutputStream());

BufferedInputStream br_socket = new BufferedInputStream(file_socket.getInputStream());

// Now a request is sent to the Listener to show all the shareable files 
// of the particular directory that satisfy the search criteria..selected
// by the user..

// To send a request a class of the name xmlwriter is used which has two 
// functions of interest they are... requestFString(String String) and
// returnRequest() this xmlwriter is a versatile class as it is used to 
// generate xml requests for various purposes... SEARCHUPLOAD DOWNLOAD 
// and SHOWFILES... therefore accordingly the requestFString takes two 
// parameters in case of SHOWFILES the second parameters is not used.

xml

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2005-03-18 12:24  Java Version

     目录          0  2005-03-18 12:24  Java VersionListener

     目录          0  2005-03-18 12:24  Java VersionListenerSource Code

     文件       3206  2005-03-18 12:24  Java VersionListenerSource CodexmlParserServer.java

     文件      10839  2005-03-18 12:24  Java VersionListenerSource CodeShareddilog.java

     文件      16523  2005-03-18 12:24  Java VersionListenerSource CodeMultiServer.java

     文件      14330  2005-03-18 12:24  Java VersionListenerSource CodeLogin.java

     文件       8878  2005-03-18 12:25  Java VersionListenerSource Codecheck_directory.java

     目录          0  2005-03-18 12:25  Java VersionListenerExecutables

     目录          0  2005-03-18 12:25  Java VersionListenerExecutablesORG

     目录          0  2005-03-18 12:25  Java VersionListenerExecutablesORGxml

     目录          0  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAX

     目录          0  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERS

     文件       1904  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSxmlReaderFactory.class

     文件       3650  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSxmlReaderAdapter.class

     文件       1179  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSxmlReaderAdapter$AttributesAdapter.class

     文件       5732  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSxmlFilterImpl.class

     文件       1020  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSParserFactory.class

     文件       9926  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSParserAdapter.class

     文件       1903  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSParserAdapter$AttributeListAdapter.class

     文件       2783  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSNamespaceSupport.class

     文件       2942  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSNamespaceSupport$Context.class

     文件        371  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSMakefile

     文件       1148  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSLocatorImpl.class

     文件       1925  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSDefaultHandler.class

     文件       4049  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSAttributesImpl.class

     文件       1975  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXHELPERSAttributeListImpl.class

     目录          0  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXEXT

     文件        170  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXEXTMakefile

     文件        499  2005-03-18 12:25  Java VersionListenerExecutablesORGxmlSAXEXTLexicalHandler.class

............此处省略1200个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)