Issue with real time random matchmaking

I want to have maximum 2 players in one room and doesn't matter which user joins whom, So I am calling opJoinOrCreateRoom at both the devices and they perfectly gets connected, when player 3 or player 4 comes and call same API then they both gets error like Error code 32765 (Game full). Since player 1 and player 2 already got connected and room got full so opJoinOrCreateRoom should have created another room where player 4 should have joined.
I am not using opJoinRandomRoom and copCreateRoom because if both the users comes starts the game same time then both creates the room and waits and no one joins, where opJoinOrCreateRoom works perfectly fine. Please suggest how to resolve the issue.


  • Hi @Harish_Kagale.

    opJoinOrCreateRoom() either creates a room with the specified name or joins it if it already exists.
    Room names are unique. No two rooms with the same name can exist at the same time.

    Hence when calling opCreateRoom() and specifying a room name that already exists, then you will receive an error that a room with that name already exists.

    opJoinOrCreateRoom() however will either create the room or join it if it already exists.

    Attempting to join a room that is either full or closed results in an according error, no matter if the join attempt has been made by a call to opJoinRoom() or to opJoinOrCreateRoom().

    So this is expected and intended behavior.

    opJoinOrCreateRoom() can not be used for joining a random room as it expects a room name.

    The recommended approach is to call opJoinRandomRoom() and if that fails because no room (with the specified criteria) exists, then call opCreateRoom().

    Yes, if two clients do this at the exact same time, then they both would not find a room and would both create their own one and then wait for a third and fourth client to join instead of getting matched against each other. However this is a rather artificial edge case that is only common during development. Once your game is live it hopefully will be played by more than just 2 users at once, so it should not really matter to much if a player gets matched against a player that comes online at the same moment or against another player that comes online a couple of seconds later.
Sign In or Register to comment.