crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.48k stars 766 forks source link

Port 8080 hardcoded when running client_aio.py, can't run on 9090 #941

Closed NumesSanguis closed 6 years ago

NumesSanguis commented 6 years ago

I want to run my Python client/publisher on port 9090 (or any other port), because some other program is running on 8080.

My project is setup as followed using Docker (following https://crossbar.io/docs/Getting-Started/):

Message broker on port 9090:

  1. git clone https://github.com/crossbario/crossbar-starter.git
  2. cd crossbar-starter/crossbar
  3. Change all occurrences of 8080 to 9090 in .crossbar/config.json and Makefile
  4. Open webbrowser on http://localhost:9090/
  5. Succesfully get JavaScript output

Python pub/sub on port 9090:

  1. cd ../autobahn-python
  2. In app/run comment python -u client_tx.py and uncomment python -u client_aio.py
  3. Open app/client_aio.py and change 2 8080 to 9090.
url = os.environ.get('CBURL', u'ws://localhost:9090/ws')
parser.add_argument('--url', dest='url', type=six.text_type, default=url, help='The router URL (default: "ws://localhost:9090/ws").')
  1. Run make start and get the following error:
make start
docker run -v /*file_path*/app:/app  -it --rm --link crossbar crossbario/autobahn-python
Traceback (most recent call last):
  File "client_aio.py", line 144, in <module>
    runner.run(ClientSession)
  File "/usr/local/lib/python3.6/site-packages/autobahn/asyncio/wamp.py", line 259, in run
    (transport, protocol) = loop.run_until_complete(coro)
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 777, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 764, in create_connection
    yield from self.sock_connect(sock, address)
  File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 451, in sock_connect
    return (yield from fut)
  File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 481, in _sock_connect_cb
    raise OSError(err, 'Connect call failed %s' % (address,))
ConnectionRefusedError: [Errno 111] Connect call failed ('172.17.0.2', 8080)
Makefile:4: recipe for target 'start' failed
make: *** [start] Error 1

Problem Seems like port 8080 is hardcoded somewhere when using asyncio version of client.

NumesSanguis commented 6 years ago

With client_tx.py it is also happening:

make start
docker run -v /*file_path*/app:/app  -it --rm --link crossbar crossbario/autobahn-python
2018-02-01T17:58:17+0000 Scheduling retry 1 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 1.58646347420017 seconds.
2018-02-01T17:58:19+0000 Scheduling retry 2 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 3.118967674364628 seconds.
2018-02-01T17:58:22+0000 Scheduling retry 3 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 3.9190793815686735 seconds.
2018-02-01T17:58:26+0000 Scheduling retry 4 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 5.189386786132975 seconds.
2018-02-01T17:58:31+0000 Scheduling retry 5 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 8.103285030929317 seconds.
2018-02-01T17:58:39+0000 Scheduling retry 6 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 12.135480982977455 seconds.
2018-02-01T17:58:51+0000 Scheduling retry 7 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 17.589164802301156 seconds.
2018-02-01T17:59:09+0000 Scheduling retry 8 to connect <twisted.internet.endpoints.TCP4ClientEndpoint object at 0x7f5adbf06be0> in 26.353133456840247 seconds.
NumesSanguis commented 6 years ago

When running everything normal (including message broker on 8080), except for changing in these 2 lines 8080 to 9090 in client_aio.py:

url = os.environ.get('CBURL', u'ws://localhost:9090/ws')
parser.add_argument('--url', dest='url', type=six.text_type, default=url, help='The router URL (default: "ws://localhost:9090/ws").')

Everything still works. This means that these values are ignored and a hard coded port is used.

om26er commented 6 years ago

When running everything normal (including message broker on 8080), except for changing in these 2 lines 8080 to 9090 in client_aio.py:

url = os.environ.get('CBURL', u'ws://localhost:9090/ws') parser.add_argument('--url', dest='url', type=six.text_type, default=url, help='The router URL (default: "ws://localhost:9090/ws").')

Everything still works. This means that these values are ignored and a hard coded port is used.

I just tried and everything is working fine for me.

The first line reads the websocket url from environment variable CBURL and fallbacks to ws://localhost:9090/ws. So you probably have CBURL in the environment.

Just replace url = os.environ.get('CBURL', u'ws://localhost:9090/ws') with url = u'ws://localhost:9090/ws' and you should have no issue.

You can ignore the port number in second line, that's just a help comment and does not affect functionality.

NumesSanguis commented 6 years ago

I changed the url as you suggested url = u'ws://localhost:9090/ws', and indeed it tries to connect over port 9090, but it still can't connect. I tried again with a fresh download and the steps I described in the first post.

crossbar.io output

make start
docker run --user 1000 -v /*file_path*/crossbar:/node -p 9090:9090 --name crossbar --rm -it crossbario/crossbar
2018-02-02T11:09:54+0000 [Controller      1]      __  __  __  __  __  __      __     __
2018-02-02T11:09:54+0000 [Controller      1]     /  `|__)/  \/__`/__`|__) /\ |__)  |/  \
2018-02-02T11:09:54+0000 [Controller      1]     \__,|  \\__/.__/.__/|__)/~~\|  \. |\__/
2018-02-02T11:09:54+0000 [Controller      1]                                         
2018-02-02T11:09:54+0000 [Controller      1] Version:     Crossbar.io COMMUNITY 17.12.1
2018-02-02T11:09:54+0000 [Controller      1] Public Key:  a1a1e70ebf2eea4ab01cb2a921f0480c2d2c3ab237b9202d8c602c16ad58208b
2018-02-02T11:09:54+0000 [Controller      1] 
2018-02-02T11:09:54+0000 [Controller      1] Node starting with personality "community" [crossbar.controller.node.Node]
2018-02-02T11:09:54+0000 [Controller      1] Running from node directory "/node/.crossbar"
2018-02-02T11:09:54+0000 [Controller      1] Node configuration loaded from "/node/.crossbar/config.json"
2018-02-02T11:09:54+0000 [Controller      1] Controller process starting [CPython-EPollReactor] ..
2018-02-02T11:09:54+0000 [Controller      1] No extra node router roles
2018-02-02T11:09:54+0000 [Controller      1] RouterServiceSession ready [no on_ready configured]
2018-02-02T11:09:54+0000 [Controller      1] Registered 20 procedures
2018-02-02T11:09:54+0000 [Controller      1] Using default node shutdown triggers ['shutdown_on_worker_exit']
2018-02-02T11:09:54+0000 [Controller      1] Configuring node from local configuration ...
2018-02-02T11:09:54+0000 [Controller      1] Starting 1 workers ...
2018-02-02T11:09:54+0000 [Controller      1] Router worker "worker-001" starting ..
2018-02-02T11:09:54+0000 [Router         16] Started Router worker "worker-001" on node "None" [crossbar.worker.router.RouterWorkerSession / CPython-EPollReactor]
2018-02-02T11:09:54+0000 [Router         16] Router worker "worker-001" session 2023671309079076 initializing ..
2018-02-02T11:09:54+0000 [Router         16] Registered 39 procedures
2018-02-02T11:09:54+0000 [Router         16] Router worker "worker-001" session ready
2018-02-02T11:09:54+0000 [Controller      1] Router worker "worker-001" process 16 started
2018-02-02T11:09:54+0000 [Router         16] RouterServiceSession ready [configured on_ready fired]
2018-02-02T11:09:54+0000 [Router         16] Realm 'realm1' started
2018-02-02T11:09:54+0000 [Controller      1] Router "worker-001": realm 'realm-001' (named 'realm1') started
2018-02-02T11:09:54+0000 [Router         16] role role-001 on realm realm-001 started
2018-02-02T11:09:54+0000 [Controller      1] Router "worker-001": role 'role-001' (named 'anonymous') started on realm 'realm-001'
2018-02-02T11:09:54+0000 [Router         16] UniSocketServerFactory starting on 9090
2018-02-02T11:09:54+0000 [Controller      1] Router "worker-001": transport 'transport-001' started
2018-02-02T11:09:54+0000 [Controller      1] Local node configuration applied successfully!

client_aio.py

make start
docker run -v /*file_path*/autobahn-python/app:/app  -it --rm --link crossbar crossbario/autobahn-python
Traceback (most recent call last):
  File "client_aio.py", line 130, in <module>
    runner.run(ClientSession)
  File "/usr/local/lib/python3.6/site-packages/autobahn/asyncio/wamp.py", line 259, in run
    (transport, protocol) = loop.run_until_complete(coro)
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.6/asyncio/base_events.py", line 786, in create_connection
    ', '.join(str(exc) for exc in exceptions)))
OSError: Multiple exceptions: [Errno 111] Connect call failed ('127.0.0.1', 9090), [Errno 99] Address not available
Makefile:4: recipe for target 'start' failed
make: *** [start] Error 1

While the javascript works fine on port 9090.