我目前正在通過以太網工作在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
**那些誰給了反對票應該評論,爲什麼?** – Sushant 2014-10-15 09:06:45
請出示您的一點VB代碼和Wireshark的包 – jeb 2014-10-16 07:19:27
@jeb哪有我向你展示wireshark數據包? – Sushant 2014-10-16 08:21:21