How to use SocketServer with IPv6

T

Tomi Hautakoski

Hello,

I'm a Python newbie trying to figure out how to use SocketServer with
IPv6. I would like to set up a TCPServer working like below but how to
tell SocketServer I need to use AF_INET6?

import SocketServer
import logging as l

l.basicConfig(level=l.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S')
PORT = 5001

class CollectorHandler(SocketServer.BaseRequestHandler):

def setup(self):
l.info('%s connected!', self.client_address)
#self.request.send('hi ' + str(self.client_address) + '\n')

def handle(self):
data = self.request.recv(1024)
l.debug('Client sent this: %s\n', data)
def finish(self):
l.info('%s disconnected!', self.client_address)
#self.request.send('bye ' + str(self.client_address) + '\n')

if __name__=='__main__':
#server host is a tuple ('host', port)
#myserver = SocketServer.ThreadingTCPServer(('', 5001), CollectorHandler)
l.info('Collector software starting up, creating TCPServer.')
try:
myserver = SocketServer.TCPServer(('', PORT), CollectorHandler)
l.info('Listening to connections in port %d.', PORT)
myserver.serve_forever()
except KeyboardInterrupt:
pass

Thanks for any advice!
 

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

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top