Search code examples
c#vb.netprocessudpbroadcastreceiver

VB.net send UDP message twice


This might sound crazy but if I am running the same process twice and I want to send the receiver a UDP message twice, so the receiver knows the process is running on the client twice. Is this possible?

'Count Process

  Dim processCount As Integer = Process.GetProcessesByName("Putty").Count()

'Send Data


   Dim client As New UdpClient()
   Dim ip As New IPEndPoint(IPAddress.Broadcast, 15000)
   Dim bytes As Byte() = Encoding.ASCII.GetBytes("GotPutty")
   client.Send(bytes, bytes.Length, ip)
   client.Close()

So if Process Count = 2, then How would I send "GotPutty" twice?


Solution

  • To send the message twice, just call client.Send twice.

    However, perhaps a better approach would be to include data in the message such as the process count - unlike TCP/IP, UDP offers no guarantees about whether messages will be received, so receiving the message once would not necessarily mean only one process is running, it might mean that the second message simply didn't reach you. If it is important for you to know that the message was received you might like to switch to TCP/IP, or send an acknowledgement (if this is not received, you would re-try the original send until you're sure the message got through ok)