Python SocketServer with IPv6

godshorse chinthakawk at gmail.com
Thu Apr 30 05:52:55 EDT 2009


On Apr 30, 1:02 pm, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> > 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.

Thank you very much Martin,

that was the one I exactly wanted to know. I was searching how I can
specify address_family.
Thanks once again.




More information about the Python-list mailing list