My ConnectionRequest run very slow

44 views
Skip to first unread message

fogan bidi

unread,
Jan 19, 2017, 4:27:33 PM1/19/17
to CodenameOne Discussions

here is an example of code that i write to make connection request. In this example, i am sending a new password to the user when ever he forget it. But i have realised that when request is sent to the server side forget.php, the email is sent automatically but the readResponse method takes too much time before displaying the Dialog, this is not a low connection problem cause i have tested it with very hight speed connection

Can you tell what to do to make readResponse method be called once the server side have done his job?



ConnectionRequest requette=new ConnectionRequest(){ Map data; @Override protected void postResponse(){ String donnees=(String)data.get("reponse"); Dialog.show("", "An email has been sent to you on "+em+"\nPlease check it to found out your password", "OK",null); } @Override protected void readResponse(InputStream input)throws IOException{ JSONParser parser=new JSONParser(); data=parser.parseJSON(new InputStreamReader(input)); } }; requette.setUrl(new ServerUrl().getServerUrl()+"/forget.php"); requette.setPost(true); requette.setTimeout(15000); requette.addArgument("email", em); requette.setDisposeOnCompletion(new LoadingDialog(new Form())); NetworkManager.getInstance().addToQueueAndWait(requette);



here is an example of how the server side script "forget.php "fis looking like:

<?php include("connexion_base.php"); $email=mysql_escape_string($_POST["email"]);
 $select
=mysqli_query(connection(),"select * from users where email='$email'"); if($r=mysqli_fetch_array($select)){ $pw=$r["pw"]; mail($email,"foganbidi","Your password is:\n$pw\n","From:foganbidi"); $sms.="Your password is:$pw"; }else{ mail($email,"foga...@gmail.com","The email you submited does not exist in our database","From:foganbidi"); $sms.="The email you submited does not exist in our database"; } $data=array("reponse"=>$sms); header("Content-Type:application/json"); echo json_encode($data);


Shai Almog

unread,
Jan 20, 2017, 12:02:24 AM1/20/17
to CodenameOne Discussions
Reply all
Reply to author
Forward
0 new messages