[英]how to make a UDP python localhost go public
I have a python localhost set up on a raspberry pi to listen for UDP packets. 我在树莓派上设置了python localhost,以侦听UDP数据包。 But I'm wondering how I can make this a public server in order to send UDP packets from roaming devices.
但是我想知道如何使它成为公用服务器,以便从漫游设备发送UDP数据包。
The below code works perfectly sending UDP packets from a device on the same wireless network. 以下代码可以完美地从同一无线网络上的设备发送UDP数据包。
import SocketServer
PORTNO = 14
class handler(SocketServer.DatagramRequestHandler):
def handle(self):
newmsg = self.rfile.readline().rstrip()
print (newmsg)
self.wfile.write(self.server.oldmsg)
self.server.oldmsg = newmsg
s = SocketServer.UDPServer(('',PORTNO), handler)
print "Awaiting UDP messages on port %d" % PORTNO
s.oldmsg = "This is the starting message."
s.serve_forever()
This is more a networking issue. 这更多是网络问题。 You will have to configure your router with appropriate port forwarding .
您将必须为路由器配置适当的端口转发 。 If your ISP does not have static IP's you may also need to set-up some dynamic DNS service.
如果您的ISP没有静态IP,则可能还需要设置一些动态DNS服务。
The NAT traversal required to connect to external networks requires a static IP outside the 192.168. 连接到外部网络所需的NAT遍历需要192.168。之外的静态IP .
。 or 10. .
或10 。 .* range.
。* 范围。 This is typically assigned by the ISP DHCP server to the external facing MAC Address of the router.
这通常由ISP DHCP服务器分配给路由器的外部MAC地址。
The port forward settings are shown here: 端口转发设置如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.