我已经写在围棋一个UDP服务器(侦听端口666),它似乎只接收由本地发出的报文。 要确认交通,我一直在使用:
sudo tcpdump -n udp dst port 666
我(略)服务器的代码:
import "net"
func startServer() {
// Bind the port.
ServerAddr, err := net.ResolveUDPAddr("udp", "localhost:666")
if err != nil {
fmt.Println("Error binding port!")
}
ServerConn, _ := net.ListenUDP("udp", ServerAddr)
defer ServerConn.Close()
buf := make([]byte, 1024)
for {
// Recieve a UDP packet and unmarshal it into a protobuf.
n, _, _ := ServerConn.ReadFromUDP(buf)
fmt.Println("Packet received!")
// Do stuff with buf.
}
}
如果,从机器的服务器上运行,我使用:
echo -n “foo” | nc -4u -w1 127.0.0.1 666
然后服务器接收该数据包,并输出该消息(和tcpdump的显示无输出)。
但是,如果我运行从网络上的另一台计算机以下内容:
echo -n “foo” | nc -4u -w1 192.168.1.134 666
然后,在tcpdump的报告正在接收的数据包( 15:05:43.634604 IP 192.168.1.113.59832 > 192.168.1.134.666: UDP, length 9
确认我的IP地址右),转到服务器没有响应。
是不是有什么特别的,我需要做的,使转至非本地请求作出回应?