TCP socket not receiving in Android service after a while -


my service receive phone call information dsl router "fritz!box". when calling, router sends phone number service @ port 1012. works, after while service not receive anymore. service running, not reason, reads nothing router. no exception thrown, service remain in while loop...

public class callmonitorservice extends service {      @override     public int onstartcommand(intent intent, int flags, int startid) {      notification notification = new notification(icon, "service", system.currenttimemillis());         intent notificationintent = new intent(this, main.class);         notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top);         pendingintent pendingintent = pendingintent.getactivity(this, 0, notificationintent, 0);         notification.setlatesteventinfo(this, "title", "text", pendingintent);         notification.flags |= notification.flag_no_clear;         startforeground(1337, notification);          new listenthread().start();     } }  class listenthread extends thread {      public void run() {          looper.prepare();          handler handler = new handler() {              public void handlemessage(message msg) {                  bufferedreader in = null;                  socket socket = new socket();                 socket.setkeepalive(true);                 socket.connect(new inetsocketaddress(inetaddress.getbyname("http://fritz.box"), 1012), 30*1000);                 in = new bufferedreader(new inputstreamreader(socket.getinputstream()), 8 * 1024);                  string line = null;                  while ((line = in.readline()) != null) {                     log.d("tag", line);                 }               }         };           handler.sendemptymessage(0);         looper.loop();     }   } 

so looks once router stops sending data loop end , handler exits handlemessage. @ point need send message handler connect , start reading data again.

also question looks might similar , deals issues when reading data on socket readline. android tcp app hanging on instream.readline()

hope helps.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -