UDP为什么接收不到数据?

hbpqwxh 2007-11-15 02:58:12
我做了一个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
请问错在哪了?
...全文
389 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbpqwxh 2007-11-27
  • 打赏
  • 举报
回复
问题已经解决,是我们的局域网禁用了!
mdmei 2007-11-19
  • 打赏
  • 举报
回复
bind 可以绑定端口
hbpqwxh 2007-11-19
  • 打赏
  • 举报
回复
有没有人知道呀?
hbpqwxh 2007-11-18
  • 打赏
  • 举报
回复
该怎样修改呀,请大侠帮忙!
zyx_hawk 2007-11-17
  • 打赏
  • 举报
回复
服务器接受数据是必须先绑定端口的,而发送方不需要

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧