HandshakeError after run 'ws listen ws://localhost:8000/hello' on macOS
ws --version ws version 0.1.0
python3 --version Python 3.10.13
`ws listen ws://localhost:8000/hello ✔ 9657 21:58:08 ExceptionGroup: all attempts to connect to localhost:8000 failed (2 sub-exceptions)
The above exception was the direct cause of the following exception:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/sangshuduo/anaconda3/lib/python3.10/site-packages/trio_websocket/_impl.py:120 in │
│ open_websocket │
│ │
│ 117 │ async with trio.open_nursery() as new_nursery: │
│ 118 │ │ try: │
│ 119 │ │ │ with trio.fail_after(connect_timeout): │
│ ❱ 120 │ │ │ │ connection = await connect_websocket(new_nursery, host, port, │
│ 121 │ │ │ │ │ resource, use_ssl=use_ssl, subprotocols=subprotocols, │
│ 122 │ │ │ │ │ extra_headers=extra_headers, │
│ 123 │ │ │ │ │ message_queue_size=message_queue_size, │
│ │
│ ╭───────────────────────── locals ──────────────────────────╮ │
│ │ connect_timeout = 5.0 │ │
│ │ disconnect_timeout = 5.0 │ │
│ │ extra_headers = None │ │
│ │ host = 'localhost' │ │
│ │ max_message_size = 1048576 │ │
│ │ message_queue_size = 1 │ │
│ │ new_nursery = <trio.Nursery object at 0x105ddcbb0> │ │
│ │ port = 8000 │ │
│ │ resource = '/hello' │ │
│ │ subprotocols = None │ │
│ │ use_ssl = False │ │
│ ╰───────────────────────────────────────────────────────────╯ │
│ │
│ /Users/sangshuduo/anaconda3/lib/python3.10/site-packages/trio_websocket/_impl.py:183 in │
│ connect_websocket │
│ │
│ 180 │ logger.debug('Connecting to ws%s://%s:%d%s', │
│ 181 │ │ '' if ssl_context is None else 's', host, port, resource) │
│ 182 │ if ssl_context is None: │
│ ❱ 183 │ │ stream = await trio.open_tcp_stream(host, port) │
│ 184 │ else: │
│ 185 │ │ stream = await trio.open_ssl_over_tcp_stream(host, port, │
│ 186 │ │ │ ssl_context=ssl_context, https_compatible=True) │
│ │
│ ╭───────────────────────── locals ──────────────────────────╮ │
│ │ extra_headers = None │ │
│ │ host = 'localhost' │ │
│ │ max_message_size = 1048576 │ │
│ │ message_queue_size = 1 │ │
│ │ nursery = <trio.Nursery object at 0x105ddcbb0> │ │
│ │ port = 8000 │ │
│ │ resource = '/hello' │ │
│ │ ssl_context = None │ │
│ │ subprotocols = None │ │
│ │ use_ssl = False │ │
│ ╰───────────────────────────────────────────────────────────╯ │
│ │
│ /Users/sangshuduo/anaconda3/lib/python3.10/site-packages/trio/_highlevel_open_tcp_stream.py:403 │
│ in open_tcp_stream │
│ │
│ 400 │ │ if winning_socket is None: │
│ 401 │ │ │ assert len(oserrors) == len(targets) │
│ 402 │ │ │ msg = f"all attempts to connect to {format_host_port(host, port)} failed" │
│ ❱ 403 │ │ │ raise OSError(msg) from ExceptionGroup(msg, oserrors) │
│ 404 │ │ else: │
│ 405 │ │ │ stream = trio.SocketStream(winning_socket) │
│ 406 │ │ │ open_sockets.remove(winning_socket) │
│ │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ _ = '' │ │
│ │ addr = ('127.0.0.1', 8000) │ │
│ │ address_family = <AddressFamily.AF_INET: 2> │ │
│ │ attempt_connect = <function open_tcp_stream.
The above exception was the direct cause of the following exception:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/sangshuduo/anaconda3/bin/ws:8 in main.""" │
│ ❱ 1157 │ │ return self.main(*args, **kwargs) │
│ 1158 │
│ 1159 │
│ 1160 class Command(BaseCommand): │
│ │
│ ╭──────── locals ─────────╮ │
│ │ args = () │ │
│ │ kwargs = {} │ │
│ │ self = <DYMGroup cli> │ │
│ ╰─────────────────────────╯ │
│ │
│ /Users/sangshuduo/anaconda3/lib/python3.10/site-packages/click/core.py:1078 in main │
│ │
│ 1075 │ │ try: │
│ 1076 │ │ │ try: │
│ 1077 │ │ │ │ with self.make_context(prog_name, args, **extra) as ctx: │
│ ❱ 1078 │ │ │ │ │ rv = self.invoke(ctx) │
│ 1079 │ │ │ │ │ if not standalone_mode: │
│ 1080 │ │ │ │ │ │ return rv │
│ 1081 │ │ │ │ │ # it's not safe to ctx.exit(rv) here! │
│ │
│ ╭───────────────────────────── locals ─────────────────────────────╮ │
│ │ args = ['listen', 'ws://localhost:8000/hello'] │ │
│ │ complete_var = None │ │
│ │ ctx = <click.core.Context object at 0x1027953f0> │ │
│ │ extra = {} │ │
│ │ prog_name = 'ws' │ │
│ │ self = <DYMGroup cli> │ │
│ │ standalone_mode = True │ │
│ │ windows_expand_args = True │ │
│ ╰──────────────────────────────────────────────────────────────────╯ │
│ │
│ /Users/sangshuduo/anaconda3/lib/python3.10/site-packages/click/core.py:1688 in invoke │
│ │
│ 1685 │ │ │ │ super().invoke(ctx) │
│ 1686 │ │ │ │ sub_ctx = cmd.make_context(cmd_name, args, parent=ctx) │
│ 1687 │ │ │ │ with sub_ctx: │
│ ❱ 1688 │ │ │ │ │ return _process_result(sub_ctx.command.invoke(sub_ctx)) │
│ 1689 │ │ │
│ 1690 │ │ # In chain mode we create the contexts step by step, but after the │
│ 1691 │ │ # base command has been invoked. Because at that point we do not │
│ │
│ ╭───────────────────────────────────────── locals ─────────────────────────────────────────╮ │
│ │ _process_result = <function MultiCommand.invoke.
Hello, First of all, are you sure your server was started before the client run? Did you try to upgrade the websocket version to the latest one?
Maybe I confuse the difference between echo-server and listen command. Since I can't see any response from echo-server when I send a text to the echo-server. However, even when I ran echo-server first, then run ws listen it still exit with ConnectionClosed error. Could you please introduce a typical scenario of how to set up a server can respond explicitly to the screen after receiving the text from a client? Thanks.