Q:

Run two webservers with twisted

I have a task to run a webserver with twisted capable of working with websockets and standard HTTP functionality. Say, I need to use websockets and connect to hostname:9000. I need to get webpage and use hostname:80/webpage to get it. How I am supposed to do it?
I tried something like:
    internet.TCPServer.__init__(self,9000, WebSocketFactory(factory))
    internet.TCPServer.__init__(self,80, server.Site(HandlerHTTP))

And it's not working: server on 80 port starts, but one at 9000 doesn't.

A:

An instance of twisted.application.internet.TCPServer represents one TCP server.  You can't initialize it twice and get two servers out of it.
I expect a more complete code snippet than you gave would look like:
from twisted.application import internet

class TwoServers(TCPServer):
    def __init__(self):
        internet.TCPServer.__init__(self,9000, WebSocketFactory(factory))
        internet.TCPServer.__init__(self,80, server.Site(HandlerHTTP))

This doesn't work.  It's like trying to have an int that is two integers or a list that is  two sequences.  Instead, make two TCPServer instances:
from twisted.application import service, internet

from websocket import WebSocketFactory

factory = ...
HandleHTTP = ...

holdMyServers = service.MultiService()
internet.TCPServer(9000, WebSocketFactory(factory)).setServiceParent(holdMyServers)
internet.TCPServer(80, server.Site(HandlerHTTP).setServiceParent(holdMyServers)

...

