Ivan,

Try the following:

- Use socket.connect(SocketAddress endpoint, int timeout).
- Catch SocketTimeoutException around connect() and use it to retry (after a delay).

It provides no benefit to try and keep the same Java object (socket), since the underlying TCP/IP data connection won't be there until the connection is established.

-- Kostya

04.01.2011 20:43, Ivan Pupkoff пишет:
Need to have "stable" connection to server.
1. The client tries to connect to server every 5 (10, N)-seconds.
2. After sucess connection client receives data from server.
3. After interrupt connection (server turn off) - go to step  # 1.

How test:
1) Start server
2) Start client (to be sure that client get data from server)
3) Stop server
4) Wait some (about 200) attempts when client tries to connect to
server.
5) Start server.

Server sends data, but client doesn't get it.
socket.connect(...) is sucessfull, but
socket.getInputStream().read(byte[]) is wrong.
Thread blocks on input.read(..).
If uncomment line
//socket.setSoTimeout(500); //to set low-level timeout for reading
then input.read(..) throws timeout Exception.


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to