0

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()
ecki
  • 780
  • 1
  • 7
  • 20

1 Answers1

1

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

whatnick
  • 5,400
  • 3
  • 19
  • 35
  • can port forwarding be done from the raspberry pi? I've set the raspberry pi to have a static ip already – ecki May 17 '13 at 05:48
  • I can provide more detailed notes on NAT traversal and Port forwarding if we know the model of your router. Note that opening ports to the outside can be a security risk. – whatnick May 20 '13 at 02:28
  • that would be great. it is a D-link dir-615. – ecki May 21 '13 at 07:27