Received: by 10.66.81.170 with SMTP id b10mr3081534pay.31.1355176338425; Mon, 10 Dec 2012 13:52:18 -0800 (PST) Received: by 10.50.135.66 with SMTP id pq2mr3224623igb.3.1355176338348; Mon, 10 Dec 2012 13:52:18 -0800 (PST) Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!kr7no8776506pbb.0!news-out.google.com!s9ni32536pbb.0!nntp.google.com!kt20no9820404pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Mon, 10 Dec 2012 13:52:18 -0800 (PST) In-Reply-To: <04e7b142-7b8d-4d58-80ba-90e0d8909297@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 69.28.149.29 References: <9a8716eb-5842-45d8-b62e-193122cd863e@googlegroups.com> <27f309f0-5118-4fa8-8b26-858d19af27de@googlegroups.com> <37e29245-591a-4325-b767-fdfe8d09a703@googlegroups.com> <04e7b142-7b8d-4d58-80ba-90e0d8909297@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Java (android) socket reconnection From: Lew Injection-Date: Mon, 10 Dec 2012 21:52:18 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:20232 artik wrote: >> try { >> sock = new Socket(); >> sock.connect(new InetSocketAddress(address, 5000), 1000); >> out = new BufferedWriter( new OutputStreamWriter(sock.getOutputStream())); > > } catch (IOException e1) { >> if( sock != null ){ Umm, no. This part belongs in a 'finally' block, not a 'catch' block. Oops. >> try { sock.close(); } catch( IOException ioex ){ >> ioex.printStacktrace(); } You need to format your code better. This is virtually unreadable. >> sock = null; With a 'final sock' variable and multiple try-catch blocks you can avoid the check for 'null' and the reset to 'null'. (You probably don't need the reset now anyway.) >> } >> } > > I don't know why yesterday - No, but today Yes - it works perfect for me. I doubt that very much. As written it is buggy. -- Lew