Search code examples
pythonsocketsubuntutornadoiptables

Tornado secure websocket timeout


My server got 2 Ip's (ip1 & ip2) i recently added ip2. When i try to open my tornado websocketserver on ip1 (where apache2 is running) everything is fine, i specify a port e.g. 22000 and can connect to my socket via wss://domain.tld:22000/sub

However as soon as i configured tornado to listen on ip2 (where apache is not running), because i have to use the port 443, which is blocked by apache on ip1, I can't connect to it via wss://sockets.domain.tld:443/sub. The DNS A record points to ip2.

The connection times out. No matter which port or protocol (wss / ws) i use.


My python code:

from tornado import web
from tornado import ioloop
from tornado import websocket
from tornado import httpserver
import ssl
import json
import random
import re
import os

application = web.Application([(r"/sub", Client)])
http_server = httpserver.HTTPServer(application,  ssl_options = {
    "certfile": os.path.join(LIB_DIR, "certificate.crt"),
    "keyfile": os.path.join(LIB_DIR, "certificate.key"),
})
http_server.bind(443, address = "ip2")
print("Listening to ip2:443")
ioloop.IOLoop.current().start()

My Server is running on Ubuntu 12.2, I opened the ports and checked with an external tool if they are open.

enter image description here

How can i fix this? Has it something to do with my server?

UPDATE I'm quite sure it has to do with http_server.bind(...), the code does work with .listen(port), but ip1 and bind does also not work.


Solution

  • According to the documentation, after the call to bind, you should call start on the server. So

    http_server.bind(443, address = "ip2")
    print("Listening to ip2:443")
    http_server.start()
    ioloop.IOLoop.current().start()
    

    should work.