Search code examples
vb.netembeddedmicrocontrollerudpclient

cannot receive UDP Packet from microcontroller


I'm currently working on a UDP communication PC <-> ARM LM3S6965 (Luminary) through the Ethernet. On the PC there is a VB.net application that simulates a UDP server/client.

When the packet is sent from the PC to the ARM LM3S6965, the packet is received without errors, but when the ARM LM3S6965 sends the UDP packet back to the PC, the packet is lost somewhere (the application doesn’t receive it).

The strange thing is that WireShark captures these packets coming to the PC and it seems they are valid.

Turning off Firewall in Windows did not help. I know that this topic might be wrong for this forum, but can anybody explain why WireShark captures these packets, but my application doesn’t? ARM LM3S6965 (192.168.0.100), PC (192.168.0.116), sending and receiving goes through port number 3040, and i am sending broadcast message from VB.Net application which is received by ARM LM3S6965 micro controller.

Here is VB.net Code:

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

Solution

  • More a comment, but it's too long ...

    No196: 42.430628
    From 192.168.0.168 -> 255.255.255.255 (From your PC to your Hardware)
    UDP ... Source Port: 63162 (63162)
    Destination Port: tomato-springs (3040)

    This looks nice and it works obviously, as your hardware send the response.

    No197: 42.431017
    From 192.168.0.100 -> 255.255.255.255 (From your hardware to your PC)
    Source Port: tomato-springs (3040)
    Destination Port: 63162 (63162)

    Why your PC should receive this packet?
    The destination Port is 63162 but you are listen to port 3040.