Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a simple peer-to-peer system in Java? [closed]

I am doing an university project. I need some sample programs on peer to peer programs in Java socket programming. Everywhere people are saying to add a server socket in the client program.

Would a single program having server socket and client socket do or do I have to create two programs of one initiating a system and another peer program running thrice to solve the problem?

I know how to do a socket program for client server model and clear on the concept. But creating a peer to peer architecture sounds complex for me to understand.

I also referred to this thread.

The person commented second says "To make peer2peer app each client opens server socket too. When client A wishes to connect to client B it just connects to its socket".

Need some more sample and an explanation on how peer to peer Java socket program works. I don't want any external API like jxta to do this task. I need a clear picture on how it works.

like image 649
Sadesh Kumar N Avatar asked Sep 12 '12 02:09

Sadesh Kumar N


People also ask

What is peer to peer programming?

Definition: pair programming Also called "peer programming," each person looks at the code the other member is writing or directly after it is written. The program logic is generally flowcharted and examined by the other team member before actual coding.

What is Java socket programming?

Socket programming in Java is used for communication between the applications that are running on different JRE. It can be either connection-oriented or connectionless. On the whole, a socket is a way to establish a connection between a client and a server.


1 Answers

Can a single program having server socket and client socket will do

Yes. In fact, that is the normal way to implement a P2P application.

But creating a peer to peer architecture sounds complex for me to understand.

There is nothing particularly complicated. A peer-to-peer program is really just a client/server program that can fulfil either role. And the "architecture" word doesn't really add much here because there is no such thing as a generic "one size fits all" peer-to-peer architecture. The label "peer-to-peer" is really about the general characteristics of the system rather than about any specific architecture, framework or API. (Though frameworks and APIs do exist ...)

However, I came across this introduction that includes some example code in Java. I don't know if this approaches the problem starting at the socket level, but to be honest if you know how to develop socket-level client / server AND you understand concurrent programming, it is straight-forward programming to put the two together to give you simple P2P.

like image 104
Stephen C Avatar answered Oct 09 '22 22:10

Stephen C