简体   繁体   中英

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?

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)

I'm just want to suggest sending the number of processes found running instead of "GotPutty".

Or send "Putty.exe|2" and split it at the | upon receiving. That way, when you receive the transmission, you are sure you have the correct amount of processes instead of risking losing packets or packets missing their destination...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM