Livechecking availablity from within client

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

Moderators: Lapo, Bax

Ludopathic
Posts: 8
Joined: 12 Nov 2016, 02:24

Livechecking availablity from within client

Postby Ludopathic » 19 Nov 2016, 14:44

Hi guys, I am using a widget library that also implements a TextField listener to check strings as I type, I was wondering if anyone had any suggestions as to how to fetch information from SFS2X in a live manner that allows me to check for availability of usernames and passwords? I would rather not try to connect directly to the postgresql database I'm runnning as I really don't want to expose it to the client.

An example would be much appreciated.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Livechecking availablity from within client

Postby Lapo » 21 Nov 2016, 08:54

Hi,
so I if I understand it correctly you would like to signal the user if the nickname is available (or not) as he types...

It should be relatively simple. From client side you can send a new "checkAvailableName" request when the user types new characters, have the server perform the check and return true/false based on what has been found.

To avoid flooding the server with too many requests you can set a minimum interval between calls of, say, 400ms. If the client types characters faster than that you wait until the interval is complete and then send again.

Makes sense?

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Ludopathic
Posts: 8
Joined: 12 Nov 2016, 02:24

Re: Livechecking availablity from within client

Postby Ludopathic » 22 Nov 2016, 11:18

OK thanks - will probably bug you a little more on this thread - the lack of java examples for clientside programming is a little hard for me, I'm having to port the example ActionScript and C# code examples I can find to java which is not always ideal :/

I have this code but this line seems to be giving me trouble and I can't fix it :

(code from http://docs2x.smartfoxserver.com/Develo ... se-recipes)

Code: Select all

var params:ISFSObject = evt.params.params as ISFSObject


this is my code so far (considering I don't know C# or AS3 I think this is as close as I can get it) :

Code: Select all

 void onExtensionResponse(SFSEvent event){
      
      ISFSObject params = new SFSObject(); //this line is not complete
      ISFSArray usersArray= params.getSFSArray("users");
      String username = new String();
      String email = new String();
      
      for (int i = 0; i < usersArray.size(); i++){
         
         ISFSObject item = usersArray.getSFSObject(i);     //edit these lines to loop through the array and compare each results with the
         username += ""+ item.getUtfString("username");  //TextField listener result.
         email += "" + item.getUtfString("email");
         
      }
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Livechecking availablity from within client

Postby Lapo » 22 Nov 2016, 12:23

No problem.
I have this code but this line seems to be giving me trouble and I can't fix it :

Code: Select all

var params:ISFSObject = evt.params.params as ISFSObject


In java it translates to:

Code: Select all

ISFSObject params = evt.getArguments("params");


Hope it helps

p.s. = we'll be adding new Java examples soon. In the mean time you can take a look at the source Android examples. Besides the Android specific code (which is not much) the usage of the API should be pretty straightforward and very similar to C# etc...

p.p.s = Also make sure you check the javadoc which contains short example of usage:
http://docs2x.smartfoxserver.com/api-do ... oc/client/
For example the SFSEvent class contains examples for all events.
Lapo

--

gotoAndPlay()

...addicted to flash games
Ludopathic
Posts: 8
Joined: 12 Nov 2016, 02:24

Re: Livechecking availablity from within client

Postby Ludopathic » 22 Nov 2016, 16:53

Hi, I assumed that that is what it would translate to and I did try it out by cross comparin the other given the other examples, however I am getting the error in the IDE that

Code: Select all

The method getArguments() in the type BaseEvent is not applicable for the arguments (String)


I'm kind of hitting my head against a wall for the moment trying to understand why this is happening.

EDIT:

I think this is actually the proper Java code, please correct me if I am wrong :

Code: Select all

      ISFSObject params = (ISFSObject) event.getArguments().get("params");
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Livechecking availablity from within client

Postby Lapo » 22 Nov 2016, 18:31

Yep, sorry forgot the cast.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 10 guests