The project I'm working on uses P2P to transfer data between peers much unlike Bittorrent. This component does a random scan on each interface to see what devices are on the network. So far it has been implemented as a Socket connection which checks whether it has succeeded in connecting by trying to connect to the program's listening port. I'm wondering if it would be faster to rip this out and do a broadcast on each interface. Would this be faster/more reliable?
The current code for connection is as follows:
Socket testSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
testSock.BeginConnect(iep, new AsyncCallback(ConnectedAsync), testSock);
for (int i = 0; i <= iterations && Thread.CurrentThread.IsAlive; i++)
{
if (testSock.Connected)
break;
Thread.Sleep(25);
}
testSock.Close(0);
The 'random' component is a simple
Random r = new Random();
for each interface's subnet.
From my experience with broadcasting (Wireshark, DHCP etc) I'm under the impression that broadcasting will be truckloads faster and use heaps less resources. The reason I ask is that the person who wrote it is a smart guy and I'm wondering why he didn't use broadcasting.
So is it worth the effort?