无法从微控制器接收UDP数据包

时间:2014-10-07 06:20:20

标签: vb.net embedded microcontroller udpclient

我目前正在开发UDP通信PC< - > ARM LM3S6965(Luminary)通过以太网。在PC上有一个模拟UDP服务器/客户端的VB.net应用程序。

当数据包从PC发送到ARM LM3S6965时,接收数据包时没有错误,但是当ARM LM3S6965将UDP数据包发送回PC时,数据包在某处丢失(应用程序无法接收数据包) )。

奇怪的是,WireShark会捕获这些来自PC的数据包,看起来它们是有效的。

在Windows中关闭防火墙没有帮助。我知道这个话题对于这个论坛可能是错误的,但任何人都可以解释为什么WireShark会捕获这些数据包,但我的应用程序却没有? ARM LM3S6965(192.168.0.100),PC(192.168.0.116),发送和接收通过端口号3040,我从VB.Net应用程序发送广播消息,由ARM LM3S6965微控制器接收。

这是VB.net代码:

Public Const mnPort As Int16 = 3040                             'Port number to send/recieve data on
Public Const msBroadcastAddress As String = "255.255.255.255"   'Sends data to all LOCAL listening clients, to send data over WAN you'll need to enter a public (external) IP address of the other client
Public udpReceivingClient As UdpClient                          'Client for handling incoming data
Public udpSendingClient As UdpClient                            'Client for sending data
Public receivingThread As Thread                                'Create a separate thread to listen for incoming data, helps to prevent the form from freezing up
Public mbiClosing As Boolean = False                            'Used to close clients if form is closing


Public Sub InitializeSender()
    udpSendingClient = New UdpClient(msBroadcastAddress, mnPort)
    udpSendingClient.EnableBroadcast = True
End Sub

Public Sub InitializeReceiver()
    udpReceivingClient = New UdpClient(mnPort)
    'Dim start As ThreadStart = New ThreadStart(AddressOf MT_Receiver)
    'receivingThread = New Thread(start)
    'receivingThread.IsBackground = True
    'receivingThread.Start()
End Sub

Public Sub MT_Send_UDP(ByVal lbTxBuffer() As Byte)

    Try
        udpSendingClient.Send(lbTxBuffer, lbTxBuffer.Length)
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

    Try
        udpReceivingClient.BeginReceive(AddressOf MT_RX_Callback, Nothing)
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Public Sub MT_RX_Callback(ByVal IR As IAsyncResult)
    Dim endPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 3040)
    Dim lbData() As Byte
    Dim llRet As UInt16
    If mbiClosing = False Then
        llRet = udpReceivingClient.Available
        lbData = udpReceivingClient.EndReceive(IR, endPoint)

        If llRet > 0 Then
            MT_Validate_Msg(lbData)
        End If

        udpReceivingClient.BeginReceive(AddressOf MT_RX_Callback, Nothing)
    End If
End Sub

Private Sub frmSearchUDP_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    mbiClosing = True

    udpReceivingClient.Close()
    udpSendingClient.Close()
    frmMain.Timer.Enabled = True
End Sub

Private Sub frmSearchUDP_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    InitializeSender()
    InitializeReceiver()

End Sub

1 个答案:

答案 0 :(得分:1)

更多评论,但它太长了......

  

No196:42.430628
  从192.168.0.168 - > 255.255.255.255(从您的PC到您的硬件)
  UDP ...源端口:63162(63162)
  目的港:番茄泉(3040)

这看起来不错,而且很明显,因为你的硬件会发送响应。

  

No197:42.431017
  从192.168.0.100 - > 255.255.255.255(从硬件到PC)
  来源港口:番茄泉(3040)
  目的港:63162(63162)

为什么你的电脑应该接收这个数据包? 目的地端口是63162,但您正在收听端口3040.