#๐Ÿ”’ websocket is closing

8 messages ยท Page 1 of 1 (latest)

sonic whale
#

trying to make a cross platform thing where my iphone streams to python
im getting this error
DEBUG:websockets.server:= connection is OPEN
INFO:websockets.server:connection open
ERROR:websockets.server:connection handler failed
Traceback (most recent call last):
File "/Users/[redacted]/Library/Python/3.13/lib/python/site-packages/websockets/asyncio/server.py", line 373, in conn_handler
await self.handler(connection)
~~~~~~~~~~~~^^^^^^^^^^^^
TypeError: handler() missing 1 required positional argument: 'path'
DEBUG:websockets.server:> CLOSE 1011 (internal error) [2 bytes]
DEBUG:websockets.server:= connection is CLOSING
DEBUG:websockets.server:< BINARY ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 48 ... 14 00 51 45 14 01 ff d9 [34318 bytes]
DEBUG:websockets.server:< CLOSE 1011 (internal error) [2 bytes]
DEBUG:websockets.server:> EOF
DEBUG:websockets.server:x half-closing TCP connection
DEBUG:websockets.server:< EOF
DEBUG:websockets.server:= connection is CLOSED

signal ruinBOT
#

@sonic whale

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

sonic whale
#
import websockets
import cv2
import numpy as np
import logging

# Configure logging for debugging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("WebSocketServer")

async def handler(websocket, path):
    
    client_ip = websocket.remote_address[0]
    logger.info(f"New connection from {client_ip}, path: {path}")

    try:
        while True:
            # Wait for data from the client
            logger.debug("Waiting for data from client...")
            data = await websocket.recv()
            logger.debug(f"Received {len(data)} bytes from {client_ip}")

            # Decode the received video frame
            frame = np.frombuffer(data, dtype=np.uint8)
            frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
            
            if frame is not None:
                # Display the video frame
                cv2.imshow("Webcam Feed", frame)

                # Exit the loop if 'q' is pressed
                if cv2.waitKey(1) == ord('q'):
                    logger.info("User requested to quit.")
                    break
    except websockets.ConnectionClosed as e:
        logger.warning(f"Connection closed with {client_ip}: {e.code} - {e.reason}")
    except Exception as e:
        logger.error(f"Unexpected error with client {client_ip}: {str(e)}")
    finally:
        # Cleanup resources
        logger.info(f"Closing connection with {client_ip}")
        cv2.destroyAllWindows()
signal ruinBOT
#

Hey @sonic whale!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
sonic whale
#
    """
    Starts the WebSocket server on the specified host and port.
    """
    server_host = "0.0.0.0"  # Listen on all available interfaces
    server_port = 8080       # Port to listen on
    logger.info(f"Starting WebSocket server on {server_host}:{server_port}...")

    # Create the WebSocket server
    async with websockets.serve(handler, server_host, server_port):
        logger.info(f"WebSocket server listening on {server_host}:{server_port}")
        await asyncio.Future()  # Run forever

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except Exception as e:
        logger.critical(f"Server failed: {str(e)}")
signal ruinBOT
#

:warning: The owner of this post is no longer in the server.

signal ruinBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.