Skip to main content

Testing the Matchmaking

Last updated on

In this section, you will learn how to run and test your Matchmaking service locally. You can test your service with your client.py files. When client.py is running, it will prompt the player to enter their username and password. Once authorized, client.py sends a a matchmaking request invokes the Lambda function. When a match is found, client.py listens to the notification service and sends a notification.

r = rq.post(
url=mm_uri,
headers={
"Authorization": f"Bearer {access_token}"
}
)
print(f"[done]: sent matchmaking request")
def print_wsm(message: str, tag: str, indent="| ", prefix="\n", suffix="\n"):
message = "\n".join([f"{indent}{line}" for line in message.rstrip().splitlines(keepends=False)])
print(f"[{tag}]:{prefix}{message}{suffix}")

async def on_message(message: str):
print_wsm(message, "recv")

scheme, uri = base_url.split("://")
ws_uri = f"wss://{uri}/lobby"

ws_client = Websockets2WSClient(
uri=ws_uri,
username=username,
password=password,
access_token=access_token
)

ws_client.listeners.append(on_message)

await ws_client.connect()
print("[done]: connect to websocket")

Now you can test your Matchmaking service. In the Python terminal, run the client.py script and enter the player's email and password. Once authorized, matchmaking will begin..