r/visualbasic • u/ZaldorNariash • Dec 22 '20
Simple UDP Receiver
Hi everyone, I am super noob, i have been using several languages only for solving various problems from art and design point of view, so no real programmer but fairly it knowledgeable.
I am now in need to create a simple tool capable of opening a UDP Socket to listen for messages sent from a machinery that sends something like this:
DATE;21/12/2020
TIME;15:13:43
MODE;NORMAL
UNIT;1
SEQ;6;0
SID;00005
PID;
ID;BORIS
TEST;LMG
OPERATOR;I have started building something, but I've got stuck as this point
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports System.Reflection
Class MainWindow
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Log.AppendText("Starting" + Environment.NewLine())
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim UDPClient As UdpClient = New UdpClient()
UDPClient.Client.ReceiveTimeout = 100
UDPClient.Client.Blocking = False
UDPClient.Client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress, True)
UDPClient.Client.Bind(New IPEndPoint(IPAddress.Any, 1200))
Try
Log.AppendText("Opening Connection" + Environment.NewLine())
Dim iepRemoteEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
Dim strMessage As String = String.Empty
Do
Log.AppendText("Loop" + Environment.NewLine())
Dim bytRecieved As Byte() = UDPClient.Receive(iepRemoteEndPoint)
strMessage = Encoding.ASCII.GetString(bytRecieved)
Log.AppendText(strMessage + Environment.NewLine())
Loop While (strMessage <> "END_RESULTS")
UDPClient.Close()
Catch ex As Exception
Log.AppendText(ex.ToString() + Environment.NewLine())
End Try
End Sub
End ClassThe interface so far (in the future i hope to implement TCP)

Any help is greatly appreciated... Thanks
P.S.
I use netcat to test the tool and send udp messages
5
Upvotes
4
u/Bittenfleax Dec 22 '20
I've done a UDP listener service before - this answer helped me complete it vb.net - Visual Basic UDPClient Server/Client model? - Stack Overflow