0

I'm looking for a way to connect two or more client sockets directly without the need for a server application running. I've searched for several ways and the best I could find is JXTA P2P protocol. I just want to know if there are any alternatives other than JXTA.

The basic functionalities of the clients interacting is (1) the ability for a client to send messages to all other clients and (2) request some file available that some other client has.

It's worth noting that I'll be running multiple instances of the application on my computer (localhost), so having NATs or firewalls aren't issues.

  • The piece of code that accepts a connection or, in the case of UDP, receives requests, **IS** the server by definition. Hence, it seems to me that what you want is logically impossible. – Ingo Apr 11 '11 at 18:07
  • So you're saying that each client should be both a client and a server that maintains a connection with all other clients? Would that be better in UDP or TCP? – Jeff Johnson Apr 11 '11 at 18:14
  • From what you tell it smells like UDP. Look, a server is just the thing that serves a request. If you want to exchange files, someone (the client) will issue a request, for example: What files are there? And he who answers, is the server. – Ingo Apr 11 '11 at 18:20
  • So for example, if a client wants a specific file it asks all running clients for the file. However, how would the client know all the available running clients if there isn't an intermediary server that keeps track of the currently online clients? – Jeff Johnson Apr 11 '11 at 18:28

2 Answers2

0

Have you looked at Hazelcast? Pretty much zero setup, gives you distributed implementations of common collections like List, Set, Map, etc, as well as a publish-subscribe mechanism. By default uses multicast communication between the nodes.

sjr
  • 9,769
  • 1
  • 25
  • 36
0

You want multicast sockets.

This question appears to have all the code you need to implement them.

Note that this is only appropriate for applications running on a LAN, which you say you have. Supporting multicast across different networks (and usually across different segments of a single large network) requires router support.

Community
  • 1
  • 1
Anon
  • 2,328
  • 12
  • 7
  • Thanks for the clarification @Anon, but what about the devices are not connected through LAN / any networks? How did they find each other? – gumuruh Jul 06 '14 at 03:04