Reading Broadcasted UDP

This is the code used to listen to broadcasted data on the local network.


Private Sub Listen()
Try
DimSTATUS as string = string.empty
Dim port As Integer = 8050
Dim done As Boolean = False
Dim listener As New UdpClient(port)
Dim groupEP As New IPEndPoint(IPAddress.Any, port)
Try
While Not done
STATUS = "Waiting for broadcast"
Dim bytes As Byte() = listener.Receive(groupEP)
STATUS = "Received broadcast from " & groupEP.ToString()
debug.print(Encoding.ASCII.GetString(bytes, 0, bytes.Length))

End While
Catch e As Exception
STATUS = "ERR: 4" & e.Message.ToString
Finally
listener.Close()
End Try
Catch ex As Exception
STATUS = "ERR: " & ex.Message.ToString
End Try

End Sub