By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

How to use SocketServer with IPv6

P: n/a
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!

--
Tomi Hautakoski
Feb 12 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.