|
-
May 6th, 2015, 05:26 PM
#1
Thread Starter
WiggleWiggle
UDP Receive Asynchronously
I am trying to asynchronously receive UDP commands from my other program. I am using the code below which works great, once. But if i resend the command, it doesn't receive it.
How do I continuously receive UDP packets?
vb.net Code:
Private Sub startListening()
ReceivingUdpClient = New System.Net.Sockets.UdpClient(listenPort)
ThreadReceive = New System.Threading.Thread(AddressOf receiveMessages)
ThreadReceive.Start()
End Sub
Private Sub receiveMessages()
Dim receiveBytes As [Byte]() = ReceivingUdpClient.Receive(RemoteIpEndPoint)
MsgBox(Encoding.ASCII.GetString(receiveBytes))
'the end goal is a Case but message box for debugging
End Sub
My usual boring signature: Something
-
May 6th, 2015, 06:01 PM
#2
Re: UDP Receive Asynchronously
Since the Receive method blocks until something arrives and the fact that it's in a worker thread, I believe all you need to do is wrap the receive in a do loop. I'm still kind of learning this stuff, so if nobody posts saying I'm not right, it means I'm learning real good.
VB Code:
Private Sub receiveMessages()
Do
Dim receiveBytes As [Byte]() = ReceivingUdpClient.Receive(RemoteIpEndPoint)
MsgBox(Encoding.ASCII.GetString(receiveBytes))
'the end goal is a Case but message box for debugging
Loop
End Sub
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 6th, 2015, 06:28 PM
#3
Thread Starter
WiggleWiggle
Re: UDP Receive Asynchronously
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|