How to break while loop android server? -
this part of server's code. got problem, can't break endless loop. it's separate class, handle client connections. how it's possible make unlimited quantity of clients connected, finish connection on button click if it's possible?
public class handler implements runnable { public void run(){ .... //sockets try{ .... //socket while (true) { client = server.accept(); count++; log.d("my log", "connected"); log.d("my log", "log" + count); executor.execute(new handler(client)); } } }
instead of using
while(true)
use like
while(myconditional) { client = server.accept(); count++; log.d("my log", "connected"); log.d("my log", "log" + count); executor.execute(new handler(client)); }
where myconditional boolean value can set in ui thread, like
button.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { myconditional = false; } });
Comments
Post a Comment