Handshake error when connecting via ws+unix

Open
#300 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
networking

Research direction

Start at ws4py.client.geventclient.WebSocketClient and its handling of ws+unix:///tmp/sock.sock, checking how host and port are populated before connect(). Reproduce the handshake with the Unix-socket example and verify that connecting works without manually assigning ws.port.

Written by the indexing model from the issue text.

Description

I have a WebSocket service that uses the gevent-websocket library. And ws4py connects to it via a Unix socket without issue.

Recently, I switched to flask-sock (uses simple-websocket under the hood) for the server.
And now handshake fails.

With trial and error (andd LLMs help), I discovered that a workaround is to set ws.port explicitly.
So, how I do it:

from ws4py.client.geventclient import WebSocketClient

_URL = "ws+unix:///tmp/sock.sock"

ws = WebSocketClient(_URL)

if ws.port is None:
    if ws.scheme == "wss":
        ws.port = 443
    else:
        ws.port = 80

ws.connect()

When the port is set, the handshake is now successful. Also, the port value is not important; even when set to "0", it works.

I see that the library always set the host (localhost in this case). Shouldn't the library also set the port?

Dominant language
Python
Stars
1.1k
Forks
285
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Lawouach/WebSocket-for-Python

All issues in Lawouach/WebSocket-for-Python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.