When I JOIN a room: On my server I receive the SFSEventType.USER_JOIN_ROOM event and on the client I receive the SFSEvent.ROOM_JOIN, as expected. When the server handles this response, it does a whole bunch of setting up for the gameExtension that is tied to that room. When my client gets the event, it sends a custom extension request (called 'start') back to the server.
Sometimes, the custom client message of "START" gets to the server before the extension is finished setting up all the states (Database calls and such). This is currently happening on my local dev environment, and I know there will be network lag when it is running in production, but I can not count on that as a fix. I can probably fix this pretty easily by having the client delay the sending of the custom START request. Perhaps decoupling it from the ROOM_JOIN event, and waiting for an actual custom READY message from the gameExtension on the server, after it is completely done setting up the extension.
What I was wondering was, is this why the joinRoom API allows us to override the fireClientEvent and fireServerEvent? Perhaps I should tell my joinRoom function to NOT send a client event, but then later artificially send that event when my room is done initialising? Can I even have the server send an artificial roomJoined event? When does the joinRoom server function send the event to the client? As soon as it detects a successful join, or after the handler has completed its code stack? (let me know if this was worded confusingly).
joinRoom event, with asynchronous client to server issues
Re: joinRoom event, with asynchronous client to server issue
When a Room gets created the Extension is initialized and then the client gets the event back, so this phase is synchronous.
Do you perform additional setup in the Server Side event? Maybe that's what is creating the asynchronous situation?
Can you better explain what you're doing?
Do you perform additional setup in the Server Side event? Maybe that's what is creating the asynchronous situation?
Can you better explain what you're doing?
-
JimmiQR
- Posts: 39
- Joined: 03 Jan 2009, 01:08
- Location: Boston, Massachusetts, United States of America
- Contact:
Re: joinRoom event, with asynchronous client to server issue
Sorry for the confusion. Room creation and extension creation is synchronous on both server and client I see (api.createRoom() returns the Room). I meant to refer only to JoinRoom events.
So the room and the extension already exist at this point. Next, the server will put one of the users into the room with the server-side api.joinRoom(user, room, roomPass, asSpectator, roomToLeave). I noticed this function returns void, leading me to believe it may be asynchronous (no boolean or anything returned).
Then the client gets the ROOM_JOIN event, and instantly sends a custom START message right back to the server.
Meanwhile, my server event handler for USER_JOIN_ROOM is still executing things. It is here where it also adds the player to game specific things, setting a game specific player class, etc. Nothing asynchronous in here, but it does (sometime) appear to finish after the client already finished its ROOM_JOIN event and sent the custom START command. So the server is receiving the message to start, where as the room join handler may not have finished yet.
So essentially, I think the server roomJoin is asynchronous, right? The client gets the event as soon as the room join is triggered, but my server code is more involved and takes longer to complete than my client room handler. If this isn't the case, I will try to examine my bug from a different perspective.
So the room and the extension already exist at this point. Next, the server will put one of the users into the room with the server-side api.joinRoom(user, room, roomPass, asSpectator, roomToLeave). I noticed this function returns void, leading me to believe it may be asynchronous (no boolean or anything returned).
Then the client gets the ROOM_JOIN event, and instantly sends a custom START message right back to the server.
Meanwhile, my server event handler for USER_JOIN_ROOM is still executing things. It is here where it also adds the player to game specific things, setting a game specific player class, etc. Nothing asynchronous in here, but it does (sometime) appear to finish after the client already finished its ROOM_JOIN event and sent the custom START command. So the server is receiving the message to start, where as the room join handler may not have finished yet.
So essentially, I think the server roomJoin is asynchronous, right? The client gets the event as soon as the room join is triggered, but my server code is more involved and takes longer to complete than my client room handler. If this isn't the case, I will try to examine my bug from a different perspective.
Re: joinRoom event, with asynchronous client to server issue
Errors are handled via exceptions, not return values.So the room and the extension already exist at this point. Next, the server will put one of the users into the room with the server-side api.joinRoom(user, room, roomPass, asSpectator, roomToLeave). I noticed this function returns void, leading me to believe it may be asynchronous (no boolean or anything returned).
I am lost here. Why do you need to listen for this event?Meanwhile, my server event handler for USER_JOIN_ROOM is still executing things.
If the join is done server side there's no use in handling the USER_JOIN room, the user is joined right after the call to the API is made.
More in general, you don't need to handle events for calls that are initiated on the server side (unless specified).
Yes, if you handle it asynchronouslySo essentially, I think the server roomJoin is asynchronous, right?
Hope it helps