Dim receivingUdpClient As UdpClient Dim receiveBytes As [Byte]() Public ThreadReceive As System.Threading.Thread Public RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0) '''' Routine to listen UDP data Public Sub ReceiveMessages() Try receiveBytes = receivingUdpClient.Receive(RemoteIpEndPoint) ''' recieve from UDP port NewInitializeThread() '' Initialise a new thread GC.Collect() Catch ex As Exception End Try End Sub Public Sub NewInitializeThread() ''' Actually this runs in a different thread AcknowledgeBack() '' Routine to acknowledgeback ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages) ThreadReceive.Start() End Sub Sub AcknowledgeBack(ByVal strIP As String, ByVal intPort As String, ByVal strHex As String) Dim strAcknowledgeHex As String receivingUdpClient.Close() SendWithUDPSocket(strIP, intPort, strAcknowledgeBytes) If Not receivingUdpClient Is Nothing Then receivingUdpClient = Nothing End If receivingUdpClient = New System.Net.Sockets.UdpClient(SocketNO) End Sub Function SendWithUDPSocket(ByVal LocalIP As IPAddress, ByVal LocalPort As Long _ , ByVal MsgBytes As Byte()) Dim _socket As Socket Try _socket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) Dim endPoint = New IPEndPoint(LocalIP, LocalPort) _socket.Bind(endPoint) Dim _remoteEndPoint As IPEndPoint _remoteEndPoint = RemoteIpEndPoint ''New IPEndPoint(GLOIP, GLOINTPORT) _socket.SendTo(MsgBytes, MsgBytes.Length, SocketFlags.None, _remoteEndPoint) _socket.Close() Catch ex As Exception MsgBox("Error - " & ex.Message) End Try _socket = Nothing 'Return _socket GC.Collect() End Function
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE