[Twisted-web] Listening on 2 addresses

Axel Rau Axel.Rau at Chaos1.DE
Fri Mar 29 12:39:37 MDT 2019


I have a simple web application with the plugin below.
It works fine with IPv4 or IPv6. The host has 2 addresses
(IPv4 + IPv6 = dual stack).
How can I extend the plugin to let my server listen on both
addresses?

Please advice,
Axel

PS: The plugin:

from zope.interface import implementer

from twisted.application.service import IServiceMaker
from twisted.application import internet
from twisted.plugin import IPlugin
from twisted.python import usage

from meteo import meteo_factory

class Options(usage.Options):
	optParameters = [	['port', 'p', 80, 'The port number to listen on.'],
						['ipv4_address', '4', None, 'The IPv4 address to listen on.'],
						['ipv6_address', '6', None, 'The IPv6 address to listen on.'],
						['host', 'l', None, 'The hostname where to listen at']]

@implementer(IServiceMaker, IPlugin)
class MeteoServiceMaker(object):
	tapname = 'meteo'
	description = 'A web application for the meteo package'
	options = Options
	
	def makeService(self, options):
		"""
		Constructs a TCP server from a factory defined in meteo.py
		"""
		return internet.TCPServer(	int(options['port']), 
                                    meteo_factory,
                                    interface=options['ipv6_address'])			

serviceMaker = MeteoServiceMaker()

---
PGP-Key:29E99DD6  ☀  computing @ chaos claudius



More information about the Twisted-web mailing list