How to check room joinable in room list?

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

hoanghuybao
Posts: 35
Joined: 22 Aug 2015, 16:20

How to check room joinable in room list?

Postby hoanghuybao » 08 Sep 2015, 18:03

Hi admin,

We can get room list using:

Code: Select all

 sfsClient.getRoomList();
and then foreach the room list to get the room name. User will try to sending request join the room

Code: Select all

sfsClient.send(new JoinRoomRequest(roomName));
, server returns an event ROOM_JOIN or ROOM_JOIN_ERROR. In case the room is full, we get an error message "Room demoRoom is full".
My question: Why do we support a method which can check room is full for example:room.isFull() before we send request to join the room?

Thanks
User avatar
Lapo
Site Admin
Posts: 20437
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to check room joinable in room list?

Postby Lapo » 09 Sep 2015, 07:56

It is not reliable on the client side, because there is always the possibility that something changes during the time between the client sends his request and when it actually gets to the server.

Imagine a situation in which both User A and User B want to join Room 1, they both see that there is one player slot free, they both send the request at the same time. Only the server can resolve this situation, and it solves it by joining the User whose request got the server first.

That's why the error is thrown by the server and the client is not reliable in this sorts of things.

Hope it helps.
Lapo
--
gotoAndPlay()
...addicted to flash games
hoanghuybao
Posts: 35
Joined: 22 Aug 2015, 16:20

Re: How to check room joinable in room list?

Postby hoanghuybao » 12 Sep 2015, 13:36

Thanks for your comment. It is good solution in this case.

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 2 guests