I think that works well.


Thanks.



On Friday, February 22, 2013 1:14:59 AM UTC-6, Tamilarasi Sivaraj wrote:
>
> Hi bob,
>  
> The Following link is help to you...This is got how to time out the socket 
> like this,
>
> *Socket socket = new Socket(ip_address, 31000);*
>
> So try this,
>
> http://stackoverflow.com/questions/4969760/set-timeout-for-socket
>
> I hope that will be help to you..
>
> Regards
> Android developer
> Trinay Technology Solutions
> www.trinaytech.com
> 5705750475
>
>
>
>
>
>
> On Thursday, February 21, 2013 8:56:59 PM UTC+5:30, bob wrote:
>>
>> I'm doing TCP, not UDP.
>>
>> Also, it is not HTTP.
>>
>> I want to set the timeout for something like this:
>>
>> *Socket socket = new Socket(ip_address, 31000);*
>>
>> Thanks.
>>
>>
>>
>>
>> On Thursday, February 21, 2013 1:08:44 AM UTC-6, Tamilarasi Sivaraj wrote:
>>>
>>> Hi bob,
>>>
>>> I don't know what you need exactly? that's like you want *Socket 
>>> timeout or HTTP timeout*.
>>> So i give the both timeout code for below you try this way.
>>>
>>>
>>> *Socket Timeout: *
>>>
>>> Try this:
>>>
>>>         try {
>>>         s = new DatagramSocket();
>>>         byte[] buf = new byte[1000];
>>>         DatagramPacket dp = new DatagramPacket(buf, buf.length);
>>>         InetAddress hostAddress = InetAddress.getByName("localhost");
>>>
>>>         String outString = "Say hi";        // message to send
>>>         buf = outString.getBytes();
>>>
>>>         DatagramPacket out = new DatagramPacket(buf, buf.length, 
>>> hostAddress, 9999);
>>>         s.send(out);        // send to the server
>>>
>>>         s.setSoTimeout(1000);   // set the timeout in millisecounds.
>>>
>>>         while(true){        // recieve data until timeout
>>>             try {
>>>                 s.receive(dp);
>>>                 String rcvd = "rcvd from " + dp.getAddress() + ", " + 
>>> dp.getPort() + ": "+ new String(dp.getData(), 0, dp.getLength());
>>>                 System.out.println(rcvd);
>>>             }
>>>             catch (SocketTimeoutException e) {
>>>                 // timeout exception.
>>>                 System.out.println("Timeout reached!!! " + e);
>>>                 s.close();
>>>             }
>>>         }
>>>
>>>     } catch (SocketException e1) {
>>>         // TODO Auto-generated catch block
>>>         //e1.printStackTrace();
>>>         System.out.println("Socket closed " + e1);
>>>
>>>     } catch (IOException e) {
>>>         // TODO Auto-generated catch block
>>>         e.printStackTrace();
>>>     }
>>>
>>> (or)
>>>
>>> *HTTP Timeout:*
>>>
>>>   
>>>  
>>> Try this:
>>>
>>> *create variables like:*
>>>
>>>     private static final long CONN_MGR_TIMEOUT = 10000;
>>>     private static final int CONN_TIMEOUT = 50000;
>>>     private static final int SO_TIMEOUT = 50000;
>>>
>>> *and use this code with httppost:*
>>>
>>>     ConnManagerParams.setTimeout(params, CONN_MGR_TIMEOUT);
>>>     HttpConnectionParams.setConnectionTimeout(params, CONN_TIMEOUT);
>>>     HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
>>>
>>> I hope this will be help to you...
>>>
>>>
>>> Regards
>>> Android developer
>>> Trinay Technology Solutions
>>> www.trinaytech.com
>>> 5705750475
>>>
>>>
>>>
>>> On Wednesday, February 20, 2013 10:58:38 PM UTC+5:30, bob wrote:
>>>>
>>>> I'm trying to set the timeout for socket activities in Android:
>>>>
>>>> System.setProperty("sun.net.client.defaultReadTimeout", "1000");
>>>> System.setProperty("sun.net.client.defaultConnectTimeout", "1000");
>>>>
>>>> Does anyone know if this works?
>>>>
>>>> I tried to test it by setting the values real low and seeing if the 
>>>> timeout happened real quick.  It looked like it didn't work, but I might 
>>>> have set them too low.
>>>>
>>>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to