Connect to many servers quickly (C#)  
Author Message
Sushisource





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

Hi everyone, I'm making a program that will run in the background on many computers in a LAN and will listen for a signal from one master client program.

My problem is that I don't know how to get the master program to quickly compile a list of all the computers that are online on the subnet, and then open multiple connections to all of the online computers.

Thus, in one sentence form, the two questions are:

1. How can I compile a list, quickly, of all the computers online on the same subnet the computer doing the searching is on

2. How do I open and maintain connections to multiple "servers" at once, so that they are ready and waiting to receive data

Thanks in advance.




.NET Development33  
 
 
Sean Hederman





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

  1. The compiling a list is generally done via a UDP broadcast/multicast. This mechanism is an efficient way of sending data simultaneously to a large number of client machines.
  2. I guess you'd then walk through the list generated by the UDP and set up standard Remoting channels to each one. Alhough, how many clients are we talking here


 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

1. How can I compile a list, quickly, of all the computers online on the same subnet the computer doing the searching is on

How to get All computers running on LAN right now http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1090093&SiteID=1

2. How do I open and maintain connections to multiple "servers" at once, so that they are ready and waiting to receive data

As some other has already suggested you can use IP Multicasting on UDP to send the same message to all those listed computers.

Or if the data to be sent to different computers differ then:

You can create multiple TCP Sockets to connect to each and then each socket will do transfer data to those computer.

(Multiple Sockets because a Socket can accept multiple connecitons at the same time but cannot connect to other Multiple sockets using a single instance)

I hope this will help.

Best Regards,

Rizwan aka RizwanSharp



 
 
Sushisource





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

Thanks to both of you, that really helps. Now that I know where to start I'm sure I can look up the specifics myself.

In reference to the first reply, about 20 clients. The data is all identical, so there should be no problem with IP Multicasting, I just have to figure out how to do that. Heh.

 
 
Sean Hederman





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

It's not actually too difficult. Read up on System.Net.Sockets.UdpClient, and in particular JoinMulticastGroup. Everything else is pure Sockets programming.



 
 
JonCole - MSFT





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

When using UDP, make sure to understand the maximum payload size for a datagram and also make sure you understand that packets may be sent in one order (a, b, c for example) and received in a different order (a, c, b for example). UDP does not guarantee delivery and nor does it provide ordering of messages (packets).

 
 
Sean Hederman





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

Yes, I try to keep UDP mesages as small as possible. If they're smaller than the packet size, then you don't have to worry about ordering as much. It shouldn't really be used for communications so much as a heads-up, giving enough information for interested parties to connect using TCP.



 
 
Sushisource





PostPosted: .NET Framework Networking and Communication, Connect to many servers quickly (C#) Top

Sean:

This is good news, because that's exactly what I'll be doing, the computers merely need to receive a single command that is their cue to begin executing a certain block of code, so it sounds like UDP is going to work out just fine.