SwapnilP
SwapnilP

Reputation: 147

HTTP setReadTimeOut can work if Network Not Available after posting data to server and waiting for responce from server

I was Posting Data from Android Mobile to Server over HTTP connection. I was able to POST data to server and also get acknowledgement from Server. But sometime if my server communication thread waiting for acknowledgement from server after posting data that time i loss Internet Connectivity and thread unable to receive Ack from server and goes in infinite loop. I tried setReadTimeOut(180000) method.

Can it work for me? Can it gives SocketTimeOutException if no network Available/ No connection between server and mobile

Upvotes: 3

Views: 723

Answers (1)

THelper
THelper

Reputation: 15619

Setting a timeout will most likely work. However, I would not recommend setting it to 180000 (= 180 seconds = 3 minutes!). 30 seconds is usually more than enough. You also might want to add a setConnectTimeout

Note that there are some situations where an HttpUrlConnection doesn't always work properly:

  1. Android versions 2.2 or earlier, better use the Apache HTTP client for these versions (see also this post)
  2. On the emulator (see also this post)

Upvotes: 2

Related Questions