我正在尝试在calamp lmu(gps跟踪设备)和我的服务器之间建立连接。 我正在使用以下代码来发送和接收数据。 我正在使用timer1从设备接收数据
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(remoteEP)
Dim returnData As String = BitConverter.ToString(receiveBytes)
txtLog.Text &= returnData.ToString & vbCrLf
Dim rep As New IPEndPoint(remoteEP.Address, C_DEVICE_LISTNING_PORT)
sktSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
sktSocket.Connect(remoteEP.Address, 20510)
sktSocket.SendTimeout = 100
'Dim udc As New UdpClient
'udc.Send(sendBytes, sendBytes.Length, rep)
'receivingUdpClient.Client.Send(sendBytes)
Catch ex As Exception
End Try
End Sub
以下两个变量是类级别:
Dim remoteEP As New IPEndPoint(IPAddress.Any, 0)
Dim sktSocket As Socket
我正在使用以下代码将数据发送到设备:
Private Sub butSend_Click(sender As Object, e As EventArgs) Handles butSend.Click
Dim sendBytes() As Byte = Encoding.ASCII.GetBytes(txtCommand.Text)
sktSocket.Send(sendBytes)
End Sub
我接收数据的代码工作正常。当设备发送数据时,timer1将其显示在文本框中。但是当我将数据发送到receivingUdpClient.Receive返回的ip地址时,它无法到达设备。但wireshark显示已发送数据。
任何帮助都会得到满足。
答案 0 :(得分:1)