Hi All,
I am trying to establish a connection through UDP to a hardware device I want to talk to. Following is my implementation on the win forms:
I catches exception and gives the error message when I try to send the data. It says: "Cannot send packets to an arbitrary host while connected."
Pl advise.
Try
Dim dataSend() As Byte = New Byte() {}
myEP = New IPEndPoint(IPAddress.Parse("192.168.2.50"), 20000)
myUDP.Connect(myEP)
If myUDP.Client.Connected Then
lblStatus.Text = "Connection successful"
End If
lblStatus.Text = "Converting Data"
dataSend = Encoding.ASCII.GetBytes(txtDatatoSend.Text)
If dataSend.Length = 0 Then
lblStatus.Text = "Send textbox cannot be left blank"
Else
lblStatus.Text = ""
End If
If myUDP.Client.Connected Then
myUDP.Send(dataSend, dataSend.Length, myEP)
End If
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
Loading
VulpesPosted Feb 9, 2012, 12:52 PM
VulpesPosted Feb 10, 2012, 11:42 AM
latika singhPosted Feb 10, 2012, 8:50 AM
Thanks for the reply! I have another concern. Is there a method to convert the bytes received from UDP into Double and display them in a textbox?
If myUDP.Client.Connected Then
Dim dataRecv() As Byte = New Byte() {}
dataRecv = myUDP.Receive(myEP)
txtReceive.Text = Encoding.ASCII.GetString(dataRecv)
End if
I want to convert this dataRecv into Double and put in a label or textbox.