java - How to ask x times TCP Client for a TCP Server data's? -
about app
in app there tcp client @ start ask server number, , it's working problem when have open connection again , ask number times server sent before other data. mean i'm trying make cycle ask x times server data , put them in recyclerview.adapter cycle goes in infinity loop without stoping after x times .
example
so if i'm starting app , reveice number 5 server ask server 1st number details after got ask 2nd number details , co.
here asynctask mainactivity code x number server @ start :
public static class connecttask extends asynctask<string, string, client> { @override protected client doinbackground(string... message) { client = new client(new client.onmessagereceived() { @override public void messagereceived(string message) { publishprogress(message); } }); client.run(); return null; } @override protected void onprogressupdate(string... values) { super.onprogressupdate(values); if(mainactivity.active){ msgserver.settextcolor(color.parsecolor("#00ff00")); msgserver.settext("online"); selfnumber = values[0]; } if(help.active){ for(int i=0; i< integer.valueof(selfnumber); i++){ stringtokenizer stringtokenizer = new stringtokenizer(string.valueof(values[0]),"#"); status = stringtokenizer.nexttoken(); receipt = stringtokenizer.nexttoken(); eur = stringtokenizer.nexttoken(); help.adapter = new selfadapter(("cassa self n°" + integer.tostring(i+1)),"eur: " + eur,"sc: " + receipt,help.img); help.selflist.add(help.adapter); help.adapterview.notifydatasetchanged(); startconnection.removecallbacks(runnableconnection); startconnection.postdelayed(runnableconnection,100); startcashmessage.removecallbacks(runnablecashmessage); startcashmessage.postdelayed(runnablecashmessage,250); } } } }
handlers :
static handler startconnection = new handler(); static runnable runnableconnection = new runnable() { @override public void run() { new connecttask().execute(""); } }; static handler startcashmessage = new handler(); static runnable runnablecashmessage = new runnable() { @override public void run() { if (help.active) { final cursor cursor = mydb.fetchdata(); if (cursor.movetofirst()) { { client.server_ip = cursor.getstring(1); } while (cursor.movetonext()); } if (client != null) { client.sendmessage("ricevo dati cassa 1"); } } } };
i think benefit learning use rxjava / rxandroid.
i believe this presentation (and video link) solution, presenting solution similar problem.
if never used rxjava before perhaps should start first presentation , video.
good luck!
Comments
Post a Comment