I have a class that listens to and sends UDP packets. For some reason,
if I listen to and send out packets via the same UdpClient object,
everything works fine. If I send out a packet on a different UdpClient
object, the data never gets there. The code is below. Can someone clue
me into the problem? Thanks.
imports System.Text.Encoding
dim oServer as New UdpClient(6501)
dim oClient as New UdpClient
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim sendBytes As Byte()
Dim As String
Dim sMessageOut As String = "test"
Do
'receive the data
sMessageIn = ASCII.GetString(oServer.Receive(RemoteIpEndPoint))
sIpAddress = RemoteIpEndPoint.Address.ToString
iPort = RemoteIpEndPoint.Port
'*****THIS DOES NOT WORK********
oClient.Connect(sIpAddress, iPort)
sendBytes = ASCII.GetBytes(sMessageOut)
oClient.Send(sendBytes, sendBytes.Length)
'*********THIS WORKS*********
oServer.Connect(sIpAddress, iPort)
sendBytes = ASCII.GetBytes(sMessageOut)
oServer.Send(sendBytes, sendBytes.Length)
Loop