websockets
                                
                                
                                
                                    websockets copied to clipboard
                            
                            
                            
                        Very basic (possibly stupid) question
Sorry for placing a question about how to use websockets here, but I didn't find another place where it would fit better.
Is it possible to run a websocket server with websockets on one computer and connect to it from another computer with a websocket client? I thought that this should naturally be working, but it does not in my case.
E.g. I run a websocket server on one computer, serving on "ws://192.168.0.xx:8765" and want to connect to it from a client which is running on a different computer which has the IP 192.168.0.yy in the same local network. But I never see any incoming connections on the server (although running logging, as described in the documentation).
I tried:
- running a websocket client on the other computer
 - using the interactive client in a cmd window on the other computer
 - using several 'websocket client' apps on my mobile (connected to the same local network)
 
The clients always say "Can't connect" and the server never reports anything. It's all running fine if I run server and client on the same computer.
So I just want to run a websocket server that sends data to a websocket client, no webpage or Javascript involved, within a local network. What am I doing wrong?
I'm using Python 3.8.9, websockets 10.3 on Windows 10 computers.
Most likely there's a firewall on the machine running the server, which blocks incoming connections. I don't know much about firewalling on Windows unfortunately.
Alternatively, your network may enforce client isolation, preventing computers from seeing each other, but that's less likely.
You can websockets out of the picture and try to establish a TCP connection with netcat.
Start a server with nc -l 5678 on one machine.
Connect a client with nc <server_ip> 5678 on the other machine, then type random lines of text once the connection is open, you should see them on the first machine. Alternatively, point a browser to http://<server_ip>:5678/ and you should see the HTTP request on the first machine. (You can even answer it manually!)
If that doesn't work (and I expect it won't), then it's a network problem, not a websockets problem.
So easy.... Yes, indeed, the Windows firewall was blocking the client. Thanks!
I have one further comment: When trying to set up the logging as described in the documentation, I got the error
File "x:\yyyy\zzz\websocketserver.py", line 62, in main
    logger=LoggerAdapter(logging.getLogger("websockets.server")),
TypeError: __init__() missing 1 required positional argument: 'extra'
So I had to change the logger argument of websocket.serve() to:
logger=LoggerAdapter(logging.getLogger("websockets.server"), None),
to get it running.
Indeed, the docs aren't correct for Python < 3.10.
Here's the fix in Python 3.10: https://github.com/python/cpython/issues/84933
I will fix the documentation.