Create and setup twisted server
    (only need to do a reactor.run() after)

    :param host: Host address to bind to (default: localhost)
    :type host: str
    :param port: Port to bind to (default: 5000)
    :type port: int
    :param debug: Should use debug mode (default: False)
    :type debug: bool
    :param observer_name: Name of twisted observer to log to stdlib
        (default: twisted)
        if None -> do not create observer
    :type observer_name: None | str
    :param flask_app: Flask object to be served (default: None)
        if None -> use imported app
    :type flask_app: flask.Flask
    :rtype: None

def create_server(
        host="localhost", port=5000, debug=False,
        observer_name="twisted", flask_app=None
):
    """
    Create and setup twisted server
    (only need to do a reactor.run() after)

    :param host: Host address to bind to (default: localhost)
    :type host: str
    :param port: Port to bind to (default: 5000)
    :type port: int
    :param debug: Should use debug mode (default: False)
    :type debug: bool
    :param observer_name: Name of twisted observer to log to stdlib
        (default: twisted)
        if None -> do not create observer
    :type observer_name: None | str
    :param flask_app: Flask object to be served (default: None)
        if None -> use imported app
    :type flask_app: flask.Flask
    :rtype: None
    """
    if observer_name is not None:
        observer = STDLibLogObserver(name=observer_name)
        globalLogBeginner.beginLoggingTo([observer])
    if flask_app is None:
        flask_app = create_app(debug=debug)

    # Create a Twisted Web resource for our WebSocket server
    ws_factory = WebSocketServerFactory(
        u"ws://{}:{}".format(host, port)
    )

    ws_factory.protocol = PluginServerProtocol
    # Needed if Hixie76 is to be supported
    # ws_factory.setProtocolOptions(allowHixie76=True)
    ws_resource = WebSocketResource(ws_factory)

    # Create a Twisted Web WSGI resource for our Flask server
    wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), flask_app)

    # Create a root resource serving everything via WSGI/Flask, but
    # The path "/ws" served by our webocket
    root_resource = WSGIRootResource(wsgi_resource, {'ws': ws_resource})

    # Create a Twisted Web Site and run everything
    site = Site(root_resource)
    # Needed if Hixie76 is to be supported
    # site.protocol = HTTPChannelHixie76Aware

    reactor.listenTCP(port, site)