9828

how to find server unavailable in android

Question:

Im developing an app which has download option

Local Server in OnState:-

From My Android Emulator,I Download Audio File and Save it in Distination Path(Local Server), Then I Played the Audio File,it Working Correct, Then My Problem

Local Server in OffState:-

While Downloading Local Server,(192.168.0.2/android/a1.mp3(Local Server Path))But it is OffState,it Still Show Loading Icon.. How Will Find Wheather Server in OffState or Onstate. Is there any delegate functions for connection fail with error

Answer1:

What you need here is to setTimeout.

Below code snipper will help you.

HttpPost httpPost = new HttpPost(url); StringEntity se = new StringEntity(envelope,HTTP.UTF_8); httpPost.setEntity(se); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters); BasicHttpResponse httpResponse = (BasicHttpResponse) httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); return entity;

Here if you dont get response within specific time limit. Code will throw ConnectTimeoutException.

Recommend

  • Http request via one network interface
  • Communicate between asyncio protocol/servers
  • Alternative to readfile()
  • AVAudioPlayer doesn't load sound
  • how to create a downloadable csv file in appengine
  • WCF hosting issues
  • How to calculate total Fridays between two dates in excel on weekly, biweekly and monthly basis?
  • Memory usage and time for execution for another process using C#?
  • Can you use multiple instances of Edge on a Selenium Grid Node?
  • How to crop a mp3 in ASP.NET + C#?
  • Soap Envelope Header in Delphi 7 not including utf-8 encoding. How can I modify it?
  • iOS - MKOverlayView custom view rect fills works, but line draws do not
  • dismiss Progress Dialog in another Activity … Android
  • Excel distinct count with conditions
  • Selectively hide background elements when overlayed with transparent div
  • Dynamically load css stylesheet and wait for it to load
  • several dataProvider per one Test in TestNG
  • Calculating ratio of reciprocated ties for each node in igraph
  • Best way to dynamically load an xml configuration file into a Flex4/Flash movie at runtime?
  • Validate child input components on submit with Vee-Validate and vue js 2
  • JQuery Internet Explorer and ajaxstop
  • Disable Enter in editText android
  • Cannot resolve symbol 'MyApi'
  • How to delay loading a property with linq to sql external mapping?
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Cannot connect to cassandra from Spark
  • javaw.exe and eclipse startup problems
  • Sending data from AppleScript to FileMaker records
  • Release, debug version and Authorization Google?
  • VBA Convert delimiter text file to Excel
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Load html files in TinyMce
  • Android Google Maps API OnLocationChanged only called once
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • How can i traverse a binary tree from right to left in java?
  • Converting MP3 duration time