Here is the applicable code from my dashboard. It uses async calls so its a little more complicated.
Code:
Sub BeginGetDataAsync() Implements IDashboardClient.BeginGetDataAsync
_listening = True
_client = New UdpClient(DS_TO_PC_LOCAL_PORT)
_client.BeginReceive(AddressOf Me.GetDataAsync, Nothing)
End Sub
Sub GetDataAsync(ByVal result As IAsyncResult) Implements IDashboardClient.GetDataAsync
Try
Dim endPoint As IPEndPoint = Nothing
Dim bytes = _client.EndReceive(result, endPoint)
ParseBytes(bytes)
Catch ex As Exception
Throw
Finally
If Listening Then
_client.BeginReceive(AddressOf Me.GetDataAsync, Nothing)
End If
End Try
End Sub