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.
Livechecking availablity from within client
-
- Posts: 8
- Joined: 12 Nov 2016, 02:24
Re: Livechecking availablity from within client
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
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
-
- Posts: 8
- Joined: 12 Nov 2016, 02:24
Re: Livechecking availablity from within client
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)
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) :
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");
}
Re: Livechecking availablity from within client
No problem.
In java it translates to:
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.
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.
-
- Posts: 8
- Joined: 12 Nov 2016, 02:24
Re: Livechecking availablity from within client
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
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
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");
Re: Livechecking availablity from within client
Yep, sorry forgot the cast.
cheers
cheers
Return to “SFS2X Java / Android API”
Who is online
Users browsing this forum: No registered users and 34 guests