收到了UDP广播应该如何回复?
Sub UdpListen()
Dim svr As New System.Net.Sockets.UdpClient(5150)
Dim buf() As Byte, sdEp As IPEndPoint
Dim cmd As String
While True
Try
buf = svr.Receive(sdEp)
Catch ex As Exception
Console.WriteLine( "广播接收出错 err: " & ex.Message)
End Try
cmd = System.Text.UnicodeEncoding.Default.GetString(buf)
'MsgBox(cmd)
Console.Write(Now)
Select Case cmd.ToUpper
Case "REQUEST SERVER NAME "
Console.WriteLine( "收到广播: " & sdEp.ToString)
'应该如何回复这个客户?
Case Else
Console.WriteLine( "未知广命令: " & cmd & ", " & sdEp.ToString)
End Select
End While
End Sub
[解决办法]
http://www.codeproject.com/vb/net/TinyUDP.asp
http://www.codeproject.com/vb/net/VbNetSendReceiveTcp.asp
有关UDP,TCP/IP的连接类。
[解决办法]
udp广播的send字段里面加上ip地址不就可以回了嘛~~~
[解决办法]
svr.NetworkStream.write()
[解决办法]
路由器为了防止网络广播风暴,是不容许跨网段广播的. 楼主可以用组播方式试试.
[解决办法]
需要路由器设置静态路由进行转发即可.