Received: by 10.224.189.16 with SMTP id dc16mr9953596qab.0.1355085367200; Sun, 09 Dec 2012 12:36:07 -0800 (PST) Received: by 10.49.95.68 with SMTP id di4mr2657979qeb.0.1355085367182; Sun, 09 Dec 2012 12:36:07 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!c8no2233759qao.0!news-out.google.com!gf5ni48614236qab.0!nntp.google.com!c8no2190193qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Sun, 9 Dec 2012 12:36:06 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=88.156.28.232; posting-account=FYIyEAoAAAANuhVTqhCgp1nBx7dpZ-nl NNTP-Posting-Host: 88.156.28.232 References: <9a8716eb-5842-45d8-b62e-193122cd863e@googlegroups.com> <27f309f0-5118-4fa8-8b26-858d19af27de@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <37e29245-591a-4325-b767-fdfe8d09a703@googlegroups.com> Subject: Re: Java (android) socket reconnection From: artik Injection-Date: Sun, 09 Dec 2012 20:36:07 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:20197 Thank You very much! Honestly. I started analyze Your code but it is partly to hard for me - I'm newbe in Java and it gives me error on invoking method "getWriter" in line: Writer w = connector.getWriter() and further exactly inside this method in line "else if( ! socket.isClosed() )". I'm going fight with this in next hours, and don't give up. One hour ago I write my code as simple as I can and in one thread - everything to avoid problem with synchronization. Effect on the server is still the same (several connection attempts after starting server when client was waiting for it) I apologize that I'm putting my code again (I hope in good format) instead try to adapt new one from You immediately, but I want to understand this problem. thrd3 = new Thread(new Runnable() { @Override public void run() { Socket sock = null; BufferedWriter out = null; while (true) { //time to rest for system try { Thread.sleep(1000); } catch (InterruptedException e2) { Thread.currentThread().interrupt(); } //attempt to send data if (sock != null) { try { out.write("TEST DATA\n"); out.flush(); } catch (IOException e) { //catch the error // ERROR----------------------- try { out.close(); sock.close(); sock = null; } catch (IOException e1) { sock = null; out = null; } } } else // if socket is null try to connect again (or firs time) { try { sock = new Socket(); sock.connect(new InetSocketAddress(address, 5000), 1000); out = new BufferedWriter( new OutputStreamWriter(sock .getOutputStream())); } catch (IOException e1) { sock = null; } } } } }); thrd3.start(); Best regards, Artik