tags:

views:

22

answers:

1

The networking application that I've written does TCP communication with N-1 (itself) other Machines in the List (N) of Machines participating in the system.

Upon application startup the application currently picks a Random Delay time (1000-3000ms) before attempting to connect to each of its peer systems

If Machine 1 attempts to Connect to Machine 2, at the same time as Machine 2 is attempting to Connect to Machine 1. Currently I just drop both connections, rechoose random times again (100-500ms) and reattempt the connections.

Each machine ultimately establishes a connection with every other machine, and the system is working, but I was thinking is there a better approach to resolving this situation?

+1  A: 

You have many options.

The usual way to break ties is to use the IP. In other words, if A connects to B just as B connects to A, the one with the lower IP can cancel its client side.

More generally, it would be best to avoid having each machine talk to each other machine, as the number of connections grows alarmingly fast. A good compromise is to use a tree structure. For example, a binary tree would mean that each machine is only responsible for connecting to two others and will only be connected to by one. Other topologies give different balances of efficiency and redundancy, so check out relevant literature on the subject.

Steven Sudit
i wish i'd prefer a complete server-client hub and spoke but alas this is what is required at the moment. The biggest network that's inplace is just 50machines so it's not too bad, but yeah the number of connections in that isn't small.
Paul Farry
At the very least, why not have a single server that everyone communicates with, so that you never need more than n connections for n machines.
Steven Sudit