2014-10-07 93 views
0

我目前正在通過以太網工作在UDP通信PC <→ARM LM3S6965(Luminary)上。在PC上有一個模擬UDP服務器/客戶端的VB.net應用程序。無法從微控制器接收UDP數據包

當數據包從PC發送到ARM LM3S6965時,數據包接收沒有錯誤,但是當ARM LM3S6965將UDP數據包發送回PC時,數據包在某處丟失(應用程序沒有收到它)。

奇怪的是,WireShark捕獲到PC的這些數據包,看起來它們是有效的。

在Windows中關閉防火牆並沒有幫助。我知道這個主題可能對這個論壇是錯誤的,但任何人都可以解釋爲什麼WireShark捕獲這些數據包,但我的應用程序沒有? ARM LM3S6965(192.168.0.100),PC(192.168.0.116),發送和接收端口號爲3040,並且我正在從ARM LM3S6965微控制器接收的VB.Net應用程序發送廣播消息。

下面是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

**那些誰給了反對票應該評論,爲什麼?** – Sushant 2014-10-15 09:06:45

+0

請出示您的一點VB代碼和Wireshark的包 – jeb 2014-10-16 07:19:27

+0

@jeb哪有我向你展示wireshark數據包? – Sushant 2014-10-16 08:21:21

回答

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)

爲什麼你的PC應該收到這個數據包?
目的端口是63162,但你聽端口3040

+0

當我將它固定到3040時,監聽端口如何改變?現在我進行了一些實驗,我保留了發件人端口3040,並將偵聽端口更改爲63162,但是當我用Wireshark目標端口將捕獲的數據包更改爲61923然後再次更改爲51120時?我如何捕獲一個數據包? – Sushant 2014-10-17 05:17:56