TCP reconnect issue

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

TCP reconnect issue

Postby Vormillion » Sat May 11, 2013 6:30 am

Hi,
I am sending every 3 seconds gps location to server.

I am testing this application, for example, I manually switch off the Internet. Then the application does not connect again (I think it is blocked by the write function). My guess is that the problem lies in the fact that the disconnection occurs after the if statement. How to solve this problem?
Here is code:
Code: Select all
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
   BufferedReader st = null;
   public void run()
   {
      try {
   st = new BufferedReader(new InputStreamReader(s.getInputStream()));
   String response ="";
                      

   boolean test= false;
   if (test=isConnected(getApplicationContext())){
      Log.v("try","Send");
      send(); // I think, here is problem
      if ((response=st.readLine()) != null && response.length()>0){
         Log.v("ok","received");
      }
      else{
      connect(); // if for example server is off
      }
                               
   }
   else{
      while(!isConnected(getApplicationContext())){
            runData(true); // reenable internet connection
      }
      connect(); // connect again after reenabled internet
   }
   } catch (IOException e) {
      e.printStackTrace();
   } catch (Exception e) {
      e.printStackTrace();
   }                        
    }
}, 0, 3000);


And here is send method:
Code: Select all
public void send() {
   try {
   DataOutputStream x = new DataOutputStream(s.getOutputStream());
   x.writeBytes("ss\n"+latitude+"\n"+longitude+"\n");
   }catch(SocketException e){
   return;
   } catch (IOException e) {
   e.printStackTrace();
   }
   
}


Please help me :)
Vormillion
Once Poster
Once Poster
 
Posts: 1
Joined: Sat May 11, 2013 6:26 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests