Python SocketServer with IPv6

Discussion in 'Python' started by godshorse, Apr 29, 2009.

  1. godshorse

    godshorse Guest

    Hello,

    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.

    Thanks in advance,
    godshorse, Apr 29, 2009
    #1
    1. Advertising

  2. > 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.
    Martin v. Löwis, Apr 30, 2009
    #2
    1. Advertising

  3. godshorse

    godshorse Guest

    On Apr 30, 1:02 pm, "Martin v. Löwis" <> 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.
    godshorse, Apr 30, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah

    IPv6 Python on Windows

    Noah, Nov 8, 2003, in forum: Python
    Replies:
    1
    Views:
    327
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Nov 8, 2003
  2. Pramod TK
    Replies:
    3
    Views:
    386
    Heiko Wundram
    Apr 27, 2006
  3. Tomi Hautakoski

    How to use SocketServer with IPv6

    Tomi Hautakoski, Feb 12, 2007, in forum: Python
    Replies:
    0
    Views:
    565
    Tomi Hautakoski
    Feb 12, 2007
  4. Thomas DiZoglio

    Windows Python 2.5.1 IPV6 problems

    Thomas DiZoglio, Feb 3, 2008, in forum: Python
    Replies:
    1
    Views:
    581
    Martin v. Löwis
    Feb 3, 2008
  5. Jesse van den Kieboom

    Ipv6 on a ipv4/ipv6 hostname

    Jesse van den Kieboom, Jun 5, 2005, in forum: Ruby
    Replies:
    1
    Views:
    340
    Dibya Prakash
    Jun 5, 2005
Loading...

Share This Page