miguelgrinberg / python-socketio

Python Socket.IO server and client
MIT License
3.96k stars 587 forks source link

CLIENT & SERVER CANNOT CONNECT# client use sockeito, which EIO=3, server use python-socketio==4.6.1 #1224

Closed qiangziakbar closed 1 year ago

qiangziakbar commented 1 year ago

Discussed in https://github.com/miguelgrinberg/python-socketio/discussions/1223

Originally posted by **qiangziakbar** August 6, 2023 from error below, I could tell that client EIO=3, ``` INFO: ('127.0.0.1', 47094) - "WebSocket /socket.io/?EIO=3&transport=websocket" 403 INFO: connection failed (403 Forbidden) INFO: connection closed ``` my server using 4.6.1, server code is like this, why my server doesnt work? it works well in websocket, but I think socketio will be better, but for now, it cannot build connection ``` import uvicorn from fastapi import FastAPI from fastapi.responses import HTMLResponse import socketio sio_client = socketio.AsyncClient() sio_server = socketio.AsyncServer( async_mode='asgi', cors_allowed_origins="*" ) sio_app = socketio.ASGIApp( socketio_server = sio_server, ) app = FastAPI() app.mount('/ws',app=sio_app) @sio_server.on("test") async def my_message(sid, data): print('test message is : ', data) await sio_server.emit("servermessage",f"test {data}") @sio_server.on("clientmessage") async def client_message(sid, data): print('clientmessage is : ', data) await sio_server.emit("servermessage",f"client sent {data}") if __name__ == "__main__": uvicorn.run("socket_main:app",reload=True,port=8000) ```
qiangziakbar commented 1 year ago

my engineio version is as below

root@VM-12-17-ubuntu:/home/ubuntu# pip show python-engineio
Name: python-engineio
Version: 3.14.2
Summary: Engine.IO server
Home-page: http://github.com/miguelgrinberg/python-engineio/
Author: Miguel Grinberg
Author-email: miguelgrinberg50@gmail.com
License: MIT
Location: /usr/local/lib/python3.10/dist-packages
Requires: six
Required-by: python-socketio
root@VM-12-17-ubuntu:/home/ubuntu# 
miguelgrinberg commented 1 year ago

Please don't write issues when you just need help with your project. Thank you.

qiangziakbar commented 1 year ago

Thank you for your help, next time I will seek help in discussion