Python SocketServer with IPv6

G

godshorse

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,
 
M

Martin v. Löwis

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.
 
G

godshorse

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top