Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to approach a very simple P2P communication program.

 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I learned how to program a client/server by using Socket and ServerSocket.

But what if neither machine is really a server or a client? Does the code running on both require having a ServerSocket, or is there another approach?

Here's a little explanation to make things a bit more clear:

I'm writing a voice chat application, starting out simple, I capture the audio then send it to another machine running the same exact program. Only I'm just using the one computer and running two different processes of the same program.

Is this what's known as "peer to peer"? Or am I confused? Can anyone please direct me on this?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server and socket are just roles that code plays. It's quite possible to have two threads, one playing client and the other playing server, then run exactly the same two JVMs and have them talk to each other. It can make it more confusing because you can't call one JVM "client" and the other JVM "server". So let's call them, um, peers!

So, yes, your design with client & server in each JVM is workable.

You might have a true "server" with a different program that introduces peers to each other. Maybe you ask it who is logged on and it gives you back a list of ServerSockets that are open on other peers. Then you can talk to other peers without using the "server" any more.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!