UDP为什么接收不到数据?
我做了一个UDP程序,可是不能互传数据,请大家帮忙!
服务器端:
Public Sub exam2()
' This constructor arbitrarily assigns the local port number.
Dim udpClient As New UdpClient
Try
udpClient.Connect(IPAddress.Parse("192.168.30.51"), 13579)
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Parse("192.168.30.51"), 13579)
Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
MessageBox.Show(("This is the message you received " + _
returnData.ToString()))
MessageBox.Show(("This message was sent from " + _
RemoteIpEndPoint.Address.ToString() + _
" on their port number " + _
RemoteIpEndPoint.Port.ToString()))
udpClient.Close()
Catch e As Exception
MessageBox.Show(e.ToString())
End Try
End Sub
客户端:
Dim udpClient As New UdpClient
Try
udpClient.Connect(IPAddress.Parse("192.168.30.51"), 13579)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
udpClient.Send(sendBytes, sendBytes.Length)
udpClient.Close()
Catch e As Exception
MessageBox.Show(e.ToString())
End Try
请问错在哪了?