MCPcopy Index your code
hub / github.com/python-websockets/websockets / start

Function start

example/tutorial/step3/app.py:88–117  ·  view source on GitHub ↗

Handle a connection from the first player: start a new game.

(websocket)

Source from the content-addressed store, hash-verified

86
87
88async def start(websocket):
89 """
90 Handle a connection from the first player: start a new game.
91
92 """
93 # Initialize a Connect Four game, the set of WebSocket connections
94 # receiving moves from this game, and secret access tokens.
95 game = Connect4()
96 connected = {websocket}
97
98 join_key = secrets.token_urlsafe(12)
99 JOIN[join_key] = game, connected
100
101 watch_key = secrets.token_urlsafe(12)
102 WATCH[watch_key] = game, connected
103
104 try:
105 # Send the secret access tokens to the browser of the first player,
106 # where they'll be used for building "join" and "watch" links.
107 event = {
108 "type": "init",
109 "join": join_key,
110 "watch": watch_key,
111 }
112 await websocket.send(json.dumps(event))
113 # Receive and process moves from the first player.
114 await play(websocket, game, PLAYER1, connected)
115 finally:
116 del JOIN[join_key]
117 del WATCH[watch_key]
118
119
120async def join(websocket, join_key):

Callers 1

handlerFunction · 0.70

Calls 3

Connect4Class · 0.90
playFunction · 0.70
sendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…