FindUserRequest() constructor

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

samuelr
Posts: 9
Joined: 31 Oct 2016, 13:19

FindUserRequest() constructor

Postby samuelr » 31 Oct 2016, 13:26

http://docs2x.smartfoxserver.com/api-do ... quest.html

The developers are using the FindUsersRequest() Constructor

When they use it multiple times it fails after the first request.

However, if the stagger it by sending them 5 secs apart it works.
Any idea what could be causing this ?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: FindUserRequest() constructor

Postby Lapo » 31 Oct 2016, 17:20

Hello,
can you be more specific and report what is the failure exactly? Is it a client side error or server side?
And what error is it?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
samuelr
Posts: 9
Joined: 31 Oct 2016, 13:19

Re: FindUserRequest() constructor

Postby samuelr » 01 Nov 2016, 14:38

Hi Lapo,

The client does not receive a response from SmartFox if the requests are sent out too close together
There are no error messages.

Client side call fails when there is No staggering between requests

Client side call succeeds after introducing a 5 sec delay between calls, which is not ideal
samuelr
Posts: 9
Joined: 31 Oct 2016, 13:19

Re: FindUserRequest() constructor

Postby samuelr » 01 Nov 2016, 18:02

Here is a general outline of our current implementation of SmartFox for the purposes of the client relaying notifications to other clients through SmartFox.


- After the client connects and joins a "Notifications" lobby, we make a SetUserVariablesRequest to set the Webkinz user ID for the user in SmartFox

var userVars:Array = new Array();
userVars.push(new SFSUserVariable("wkName", _notificationService.userId));
_sfs.send(new SetUserVariablesRequest(userVars));

- When we need to notify another user, requests get placed into a queue, and we process them one by one

- First, we send a FindUsersRequest specifying the other users Webkinz ID to find out their assigned SmartFox ID

var exp:MatchExpression = new MatchExpression("wkName", NumberMatch.EQUALS, wkID);
_sfs.send(new FindUsersRequest(exp));

- Once the SFSEvent from the FindUsersRequest is received we check if an online user was found and we send a PrivateMessageRequest to them, specifying the SmartFox user ID as the destination user


The part that caused issues for us was when the client is told to notify multiple users. In this case we still queue the processing and handle notifying one user at a time, but still when we did not have a delay there would be scenarios where the FindUsersRequest would be sent out and we would never receive an SFSEvent.USER_FIND_RESULT event from SmartFox.

When we added a one second delay after processing one request before going on to the next one, the event would always come through successfully.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: FindUserRequest() constructor

Postby Lapo » 02 Nov 2016, 09:07

From the client side there is a limit of one FindUserRequest per second, to avoid spamming from malicious users.
If you take a look at the server side logs you will notice that an error is generated if you send more than 1 FindUserReq per second.

If you need to run multiple searches per second I would recommend two possible ways:

1- run a single client side "FindUser" with a compounded MatchExpression. E.g.

Code: Select all

var searchExp:MatchExpression = new MatchExpressions("name", StringMatch.EQUALS, "name1").or("name", StringMatch.EQUALS, "name2")... etc...
.
This way you can search any number of users with a single request

2- run a server side search, which has not time limits. In other words, you can send all the IDs that need to be searched to your custom Extension and perform the FindUser call from server side. Once again it would be best to optimize the search by aggregating the IDs in the MatchExpression.

Running the FindUserRequest from server side is done via

Code: Select all

getApi().findUser(...);

More details are found in the javadoc:

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
aliko
Posts: 117
Joined: 09 Mar 2013, 16:26

Re: FindUserRequest() constructor

Postby aliko » 14 Nov 2016, 20:32

How can we send the result of user list findUser(..) to client?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: FindUserRequest() constructor

Postby Lapo » 15 Nov 2016, 08:07

You can serialize the User object by calling toSFSArray().

Like this:

Code: Select all

List<User> userList = getApi().findUser(...);

ISFSObject resObj = new SFSObject();
ISFSArray userListData = new SFSArray();

for (User user : userList)
{
   userListData.addSFSArray(user.toSFSArray());
}

resObj.putSFSArray("UserList", userListData);

send("response", resObj, targetUser);


On the client side you can loop through the SFSArray and build a User list by calling SFSUser.fromArrayList(...) and passing each item of the array.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Alexwek and 105 guests