Python SocketServer with IPv6

"Martin v. Löwis" martin at v.loewis.de
Thu Apr 30 02:02:14 EDT 2009


> I am working on a overlay network implementation with python. I need
> to use both IPv4 and IPv6 at each node. Python socketserver is being
> used for this task. can anybody pls suggest me how to input an IPv6
> address to the socketserver.

I'm not quite sure I understand the question, so here is a complete
example

import SocketServer, socket

class SimpleHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        print "Received connection from", self.client_address
        self.request.send("Hello\r\n")

class V6Server(SocketServer.TCPServer):
    address_family = socket.AF_INET6

s = V6Server(("::",4444), SimpleHandler)
s.serve_forever()

Hope this helps,
Martin

P.S. I recommend to dual-stack sockets, i.e. to turn off the
IPV6_V6ONLY socket option, and to bind to both v4 and v6 interfaces.



More information about the Python-list mailing list