Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #20203

Re: Java (android) socket reconnection

Received by 10.224.105.205 with SMTP id u13mr10247280qao.6.1355093130908; Sun, 09 Dec 2012 14:45:30 -0800 (PST)
Received by 10.49.34.135 with SMTP id z7mr2720270qei.1.1355093130895; Sun, 09 Dec 2012 14:45:30 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!c8no2205092qao.0!news-out.google.com!gf5ni48613681qab.0!nntp.google.com!c8no2249208qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.programmer
Date Sun, 9 Dec 2012 14:45:30 -0800 (PST)
In-Reply-To <ka323a$t8v$1@dont-email.me>
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> <ka2c97$ag8$1@dont-email.me> <27f309f0-5118-4fa8-8b26-858d19af27de@googlegroups.com> <ka2k1v$l3$1@dont-email.me> <37e29245-591a-4325-b767-fdfe8d09a703@googlegroups.com> <ka323a$t8v$1@dont-email.me>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <d5c6a0b4-a9da-4060-8c04-912d8368c415@googlegroups.com> (permalink)
Subject Re: Java (android) socket reconnection
From artik <olsztyn.arti@gmail.com>
Injection-Date Sun, 09 Dec 2012 22:45:30 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.java.programmer:20203

Show key headers only | View raw


Thank you again for your advising - it is worth for me so much.
When we back to your code and checking null, is my "improvement" your code good:
         @Override 
            public synchronized Writer getWriter() 
                throws IOException 
            { 
                if( disposed ){ 
                    throw new IOException( "Connector is closed" ); 
                } 

                if( socket != null && ! socket.isClosed() ){ 
                    assert writer != null; 
                    return writer; 
                } 
                else if( socket != null ){ 

It's working but:( sometimes new null error happens in different place (some lines below - in my project it is 125th row of your code):

     this.socket = sc.socket(); 

Here you are description:
12-09 22:06:52.982: E/AndroidRuntime(1387): FATAL EXCEPTION: Thread-9
12-09 22:06:52.982: E/AndroidRuntime(1387): java.lang.NullPointerException
12-09 22:06:52.982: E/AndroidRuntime(1387): 	at com.example.aj.siec.ConnectionsExample$1.getWriter(ConnectionsExample.java:125)
12-09 22:06:52.982: E/AndroidRuntime(1387): 	at com.example.aj.siec.ConnectionsExample$Poller.run(ConnectionsExample.java:50)
12-09 22:06:52.982: E/AndroidRuntime(1387): 	at java.lang.Thread.run(Thread.java:1019)


Beside this your proposition of code is almost perfect! Almost, because I can't reduce time of reconnection (like in my simple code using timeout for breaking attempt of connection). After long time waiting for server, after I turn on it - only one attempt (not like in my code over a dozen ) is taking but time (from the moment I turn on server) for waiting on connection takes about 50-70seconds with only waiting for set connection.

I think my code beside point what you were show, is bad because I think it have works in schema:
1. server is switched off
2. client tries to connect to server but attempt fails
3. client closes socket and try again point.2 until pass to connect
4. only last (succesfull) attempt connects to server is initializing rest of connection.

But in my "sad" example - it looks like all attempts from point are remember and when point 3 happend they try to connect again and immediately finish after connection - for the rest of the time only one of them (I mean last and (pass attempt) continues connection. Beside problem of strange attempt for connect after server woke up is that it is crush my application still - but the time is needed some longer than before.

Regards,
Artik

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 07:06 -0800
  Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-09 16:55 +0100
    Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 08:26 -0800
      Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-09 19:07 +0100
        Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 12:36 -0800
          Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-09 23:07 +0100
            Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 14:45 -0800
              Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-10 00:47 +0100
            Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-10 13:09 -0800
              Re: Java (android) socket reconnection Lew <lewbloch@gmail.com> - 2012-12-10 13:52 -0800
    Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 08:34 -0800
  Re: Java (android) socket reconnection Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-09 11:09 -0500
    Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 08:33 -0800

csiph-web