Hi,

I have a project on peer-to-peer file transferring...Now I don't have any clue how I can use just the IP address of a computer to search for files in different drives...I have used socket object to create clients...now I have the info of only IP address and port number of a client. I need to search other clients' hard drive for particular files that the client selects...
Is there any built-in java method or how can I develop a mechanism to do so?
please guys, if you do have a solution, let me know...
My deadline is approaching...

Thanx in advance for your time...

Razib

Dani AI

Generated

A few clarifications and a practical plan that build on the ideas from , and without repeating earlier short suggestions.

You cannot "send a thread" over the network and have it execute on another machine. Threads are in-process objects. To run searches remotely you must run code on the remote peer (an always-on agent, a service invoked via RMI/HTTP/SSH, or a preinstalled executable). Mobile-code schemes exist, but they are complex and unsafe for a student project.

A simple, reproducible architecture for a class project

  • Install a small agent on each peer that exposes a restricted search API (HTTP+JSON is easiest).
  • The agent keeps a lightweight index (Lucene for real text search, or a simple file-name index + WatchService for incremental updates; see Apache Lucene and the Java WatchService API at (https://docs.oracle.com/javase/8/docs/api/java/nio/file/WatchService.html)).
  • A coordinating server forwards search requests (or the client multicasts them). Agents return metadata only (path within allowed folders, size, hash) and a download endpoint. Actual transfer happens after permission/authentication.

Example request/response (JSON):

# client -> peer
{ "type":"search", "q":"invoice", "max":50, "token":"<auth>" }

# peer -> client
[{ "path":"Shared/docs/invoice.pdf", "size":123456, "sha256":"..." }]

Minimal Java search example (uses Java NIO):

public List<Map<String,Object>> search(Path root, String term) throws IOException {
  try (Stream<Path> s = Files.walk(root)) {
    return s.filter(Files::isRegularFile)
            .filter(p -> p.getFileName().toString().toLowerCase().contains(term.toLowerCase()))
            .map(p -> Map.of("path", p.toString(), "size", Files.size(p)))
            .collect(Collectors.toList());
  }
}

Practical cautions

  • Do not expose full drives. Provide explicit shared folders or allowlists and require user consent.
  • Use TLS, tokens, and per-request authorization.
  • For large files implement chunked transfer with checksums and resume support (HTTP range or custom protocol).
  • NAT/firewall: use a central rendezvous server or relay if direct peer-to-peer connections fail.

Implementation milestones: agent + local index -> simple search API -> secure download endpoint -> add indexing and resume support -> handle NAT traversal. This progression keeps the project manageable and testable.

Recommended Answers

All 4 Replies

Hi Everyone,

Streams is the answer.

You have to have a folder(easier than searching the entire hd) then send a list and the other side gets it and do the appropriate transfer.

ps: You have to create your own format of data packets for transfer

Richard West

hmm, I think he wants far more.
He seems to want to get a complete directory structure of someone's harddisk (with all files involved) from a remote location.
That is (happily) impossible.

What is possible is asking a program on the other computer (in a P2P environment you'd have programs running on both computers after all) for a specific file and have that program search for it.

Guys,

Let me make the point clear. I need to build a peer-to-peer file transfer system, where a client uses a program to enter a search string and the server checks the other clients' computer for that file. The security measures will be considered later. First I have to develop the basic system.

My point is now how I can search in other computers using only the socket information. Of course, the client whose PC is being searched, agrees to proceed by logging in to server.

It is one of our 3r year projects. Now I am asking for a feasible mechanism to implement the searching and then begin transferring. Can you help me with some idea or any hint that I can use...

Now one thing that came to my mind after reading your posts is that if I send every client a thread containing the search string, then the thread will search its localhost drives for a match..then it can send the result back to the server. Is it possible to implement? Then I have to develop a local searching mechanism and then worry about transferring the file. Will the thread be able to transfer the file to server or other PCs? :eek:


Thanks a lot guys for replying...Looking forward to hear you...

Razib

You don't do it like that.
Either you have each client send a complete description of their filesystems to the server when first signing up and later regular updates and do all the searching on the server OR (and that's the best way) you have the server marshall the requests and have each client perform the actual search and send the results back to the server for return to the client initiating the search.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.