• 大小: 2.93MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-27
  • 语言: Java
  • 标签: 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 Version\Listener

     目录          0  2005-03-18 12:24  Java Version\Listener\Source Code

     文件       3206  2005-03-18 12:24  Java Version\Listener\Source Code\xmlParserServer.java

     文件      10839  2005-03-18 12:24  Java Version\Listener\Source Code\Shareddilog.java

     文件      16523  2005-03-18 12:24  Java Version\Listener\Source Code\MultiServer.java

     文件      14330  2005-03-18 12:24  Java Version\Listener\Source Code\Login.java

     文件       8878  2005-03-18 12:25  Java Version\Listener\Source Code\check_directory.java

     目录          0  2005-03-18 12:25  Java Version\Listener\Executables

     目录          0  2005-03-18 12:25  Java Version\Listener\Executables\ORG

     目录          0  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml

     目录          0  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX

     目录          0  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS

     文件       1904  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\xmlReaderFactory.class

     文件       3650  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\xmlReaderAdapter.class

     文件       1179  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\xmlReaderAdapter$AttributesAdapter.class

     文件       5732  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\xmlFilterImpl.class

     文件       1020  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\ParserFactory.class

     文件       9926  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\ParserAdapter.class

     文件       1903  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\ParserAdapter$AttributeListAdapter.class

     文件       2783  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\NamespaceSupport.class

     文件       2942  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\NamespaceSupport$Context.class

     文件        371  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\Makefile

     文件       1148  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\LocatorImpl.class

     文件       1925  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\DefaultHandler.class

     文件       4049  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\AttributesImpl.class

     文件       1975  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\HELPERS\AttributeListImpl.class

     目录          0  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\EXT

     文件        170  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\EXT\Makefile

     文件        499  2005-03-18 12:25  Java Version\Listener\Executables\ORG\xml\SAX\EXT\LexicalHandler.class

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

评论

共有 条评论