9

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sadesh Kumar N
  • 1,962
  • 7
  • 19
  • 26

1 Answers1

13

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.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216