Session ID differences between client and server #1275
-
I have the following code: import time
import socketio
sio_client = socketio.Client()
@sio_client.event
def on_connect(sid: str) -> None:
"""Connect event from server emits its SID to this function."""
print(f"server connect SID: {sid}.")
sio_client.connect("http://127.0.0.1:8000", socketio_path="/ws/socket.io")
print(f"client connect SID: {sio_client.sid}.")
time.sleep(0.1)
sio_client.disconnect() Running this code with
Why is the server's session ID different from the client's session ID? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You are mixing up two different identifiers. The Socket.IO protocol assigns an identifier to the Engine.IO transport, and a different one for each connected Socket.IO namespace. The |
Beta Was this translation helpful? Give feedback.
You are mixing up two different identifiers. The Socket.IO protocol assigns an identifier to the Engine.IO transport, and a different one for each connected Socket.IO namespace. The
sid
that you get in the server on theconnect
handler is the Socket.IO identifier. But thesio_client.sid
that you are printing on the client is actually a private variable of the client, not supposed to be used by the application. Instead, usesio_client.get_sid()
to get the identifier for the Socket.IO session associated with the default namespace. documentation link