1

I am looking to send a short message to all IP's on a subnet in C#. I am using a TCPClient and the problem is that the TCPClient.Connect() function takes a good 20 seconds to throw it's Exception if there is nothing using that IP. I would hoping for something on the order of a couple of milliseconds if possible.

All I am really looking to do is send a couple bytes to each address and receive an ACK from certain ones. If there is a way to do this without explicitly using the Connect(), the TCPClient, or even just setting a Connection timeout that I don't know about, I could easily switch to that instead.

I'm looking to run this program on multiple computers and this broadcast is going to be used so that each instance will know the IP's of the other instances. So really all I need is to send a couple bytes for identification.

user912447
  • 696
  • 1
  • 11
  • 31
  • Can you use UDP? What types of messages do you need to send? [C# Socket connect timeout](http://stackoverflow.com/questions/1062035/how-to-config-socket-connect-timeout-in-c-sharp) – drew010 Feb 04 '12 at 04:27
  • Yeah I can use UDP. I only have to send a couple bytes. Is it faster? – user912447 Feb 04 '12 at 04:38

2 Answers2

4

Why not broadcast over a UDP address instead. If the clients are listening on that address they'll get the message (although it's not guaranteed like TCP) if they're not there, the broadcaster doesn't care. It sounds like what you need is UDP which is more of a broadcast to anyone that's listening scenario.

Mark W
  • 3,879
  • 2
  • 37
  • 53
1

Depending on whether you actually need the response back quickly or whether you just need control to return to your program, you could do it asynchronously.

Brandon Moore
  • 8,590
  • 15
  • 65
  • 120