Results 1 to 11 of 11
Thread: P2P network in Java
- 09-08-2008, 01:05 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
P2P network in Java
Hello to everyone.
I am trying to create a napster-like p2p network. It consists of an index server with known IP and port holding meta-data about every shared file. A peers connects to this server and searches for a file. The server gives to the peer information on which peer has the file (providing his IP and port) and then the asking peer connects with the 'target' peer and copies/downloads the file to his shared folder. The question is the following: how can I achieve peer-to-peer communication ie. not via the Server but directly from a peer to another peer. Can someone give me a clue (some lines of code) on how a process can make connections and also recieve connection calls?
Thank you for your time!
- 09-08-2008, 02:12 PM #2
For one machine to connect to another it needs the IP address of the other machine. One side needs to act as server(opens socket to receive a connection) and one act as client (opens socket to connect to server).
Look at the ServerSocket and Socket classes for making connections.
- 09-08-2008, 03:53 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Thank you for your reply Norm. Actually I knew the way to make conections. Let me express again my question: I want to use two different programs: one fo peers and one for server. The server program is threaded: it waits until a connection from a peer is made and then a child process is spawned and serves peer's request. At some point during peer-server communication, the peer will have to communicate with another peer to recieve the file specified by the server. This is not done via the server but rather in direct peer-to-peer communication. This means that the other peer must wait for a connection attempt (just like the server) and do nothing until another peer connects with it. This is not what I want since a peer cannot concurrently search for files and wait for requests from another peers. It is either the one or the other since method '.accept()' used by Server sockets "freezes" a process which cannot go further until a conection is made. I was wondering if peer process can be threaded but I'm having difficulties. Can someone provide a simple code solution?
- 09-08-2008, 04:26 PM #4
It could if the two tasks were on separate threads.since a peer cannot concurrently search for files and wait for requests from another peers
If you have a server that is using threads, can you write another program that uses threads. One thread to wait on an accept and the other to do the search.
- 09-08-2008, 05:01 PM #5
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
Yes, this is excactly what I'm trying to find: a correct syntax for such a program. Can you provide some help with the code (just the thread excecution not the rest)? Write if you can a small example (not necessarily working).
Thank you
- 09-08-2008, 05:58 PM #6
There have been several examples posted on this forum.
Use Search for Thread.
Java Code:Thread t = new Thread(new Runnable() { public void run() { // do it here } }); t.start(); // start the thread
- 09-10-2008, 07:52 PM #7
Member
- Join Date
- Sep 2008
- Posts
- 4
- Rep Power
- 0
I really thank you Norm for your help. I managed to find a way out.
- 09-23-2008, 01:47 PM #8
Member
- Join Date
- Aug 2008
- Posts
- 12
- Rep Power
- 0
i think JXTA is a best option to start P2P network.
you have full control over all the standered network protocols if go through this.
- 09-24-2008, 03:24 AM #9
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
- 09-24-2008, 03:30 AM #10
Can you post the link to the doc for that API? I don't remember it.
Thanks.
- 10-01-2008, 08:22 PM #11
Senior Member
- Join Date
- Sep 2008
- Posts
- 135
- Rep Power
- 0
Download the source for Azureus and have a look at the torrent engine they use. If you're asking this question, you're not up to the job of writing a reliable protocol yourself. Even if you were up to it, why bother? You'll have plenty other things to worry about in your app, let someone else do the heavy lifting of socket management
Similar Threads
-
Java Based Application to Map Network Drive
By Wraithier in forum New To JavaReplies: 15Last Post: 05-24-2012, 11:09 AM -
[SOLVED] executing java over network
By jmHoekst in forum New To JavaReplies: 6Last Post: 06-30-2008, 05:58 PM -
database+network
By hidar in forum JDBCReplies: 4Last Post: 06-30-2008, 09:04 AM -
best Java Network API to use?
By San_Andreas in forum NetworkingReplies: 1Last Post: 04-30-2008, 08:42 PM -
Getting network card address in Java 6
By Java Tip in forum Java TipReplies: 0Last Post: 03-02-2008, 07:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks