You need to bind the UdpClient
to a local port before you call Send()
. The only way to specify the source port is in the UdpClient
's constructor, so if you do not know which source port to use until you have received a message first then you will have to wait until then before creating the UdpClient
.
Private Sub UdpSend(ByVal txtMessage As String)
Dim pRet As Integer
Dim MyUdpClient as UdpClient = new UdpClient(8082); ' <-- here
MyUdpClient.Connect(IPAddress.Parse(IpRemotaLbl.Text), RemotePortLbl.Text)
bytCommand = Encoding.ASCII.GetBytes(txtMessage)
pRet = MyUdpClient.Send(bytCommand, bytCommand.Length)
'Console.WriteLine("No of bytes send " & pRet)
PrintLog("No of bytes send " & pRet)
End Sub