سؤال

I have a python localhost set up on a raspberry pi to listen for UDP packets. But I'm wondering how I can make this a public server in order to send UDP packets from roaming devices.

The below code works perfectly sending UDP packets from a device on the same wireless network.

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.

The NAT traversal required to connect to external networks requires a static IP outside the 192.168.. or 10...* range. This is typically assigned by the ISP DHCP server to the external facing MAC Address of the router.

The port forward settings are shown here: D_Link port forward

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top