This discussion is archived
1 2 3 Previous Next 31 Replies Latest reply: Jun 2, 2013 7:50 AM by Murray9654 RSS

socket.getOutputStream getting blocked for significant amount of time?

Murray9654 Newbie
Currently Being Moderated
Hi I have written the following code for server application:-
SSLServerSocket ss=(SSLServerSocket)sslssf.createServerSocket(Constants.CHAT_SERVER_PORT);
final String[] enabledCipherSuites = { "SSL_DH_anon_WITH_RC4_128_MD5" };
ss.setEnabledCipherSuites(enabledCipherSuites);         
while(true) {
    Socket s=ss.accept();
    OutputStream out=s.getOutputStream();
    ObjectOutputStream oos=new ObjectOutputStream(out);
    oos.flush();
    Android android=new Android();
    oos.writeObject(android);
    InputStream sis= s.getInputStream();
    ObjectInputStream ois=new ObjectInputStream(sis);
}
Everything is going fine. But "OutputStream out=s.getOutputStream();" in the above code is taking signifacant amount of time. Nearly one minute. I am not sure why? Please help me solving this problem.

This is happening on Android._
  • 1. Re: socket.getOutputStream getting blocked for significant amount of time?
    gimbal2 Guru
    Currently Being Moderated
    Muralidhar wrote:
    This is happening on Android._
    So ask in an Android/Dalvik forum where people who actually have knowledge of your runtime environment will visit. You don't have a problem with Oracle Java, you have a problem with Google Dalvik and/or the Android runtime environment. But the fact that Google decided to abuse the Java language tends to confuse people, you're not alone getting lost.

    Needless to say that a common source of misery in regular PC environments under Oracle Java is generally not related to code but to dodgy network settings - which is not so hard to reason since there isn't much code to actually creating the socket connection to begin with. Any number of things can be wrong there, its beyond the scope of a programming forum to help debug your network settings.
  • 2. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    The worst thing with Android is , they are displaying https://groups.google.com/forum/?fromgroups#!forum/android-developers as the official forum for developers. But I have posted few questions and none appeared in the forum. For new joiners the moderator has to approve. I dont know what happens but none of my posts appeared on that forum. vexed up with those.
  • 3. Re: socket.getOutputStream getting blocked for significant amount of time?
    EJP Guru
    Currently Being Moderated
    That will be the SSL handshake taking the time, but why are you using an anonymous cipher suite? Are you aware it's insecure?
  • 4. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    I am not sure but handshake should happen when the socket gets connected itself. I mean with
    ss.accept()
    but the problem is with
     socket.getOutputStream()
    . why i am saying this is we are running two SSL clients against this server code. This is the problem with one of the client. The second does not have any problem. Still need to have a deep look into the issue. Once i found something accurate i will post back again here. At later stage i will not be using anonymous cipher suite.
  • 5. Re: socket.getOutputStream getting blocked for significant amount of time?
    EJP Guru
    Currently Being Moderated
    I am not sure but handshake should happen when the socket gets connected itself. I mean with
    ss.accept()
    No. It happens at the first I/O.
    but the problem is with
     socket.getOutputStream()
    .
    That's when it happens.
  • 6. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    Ok Thank you so much. But i need to find out why this is happening with one and not happening with other.
  • 7. Re: socket.getOutputStream getting blocked for significant amount of time?
    EJP Guru
    Currently Being Moderated
    Are the clients Android? or the server? or both? Whichever one isn't, run it with -Djavax.net.debug=ssl,handshake and watch the output carefully to see where the delay is. Try that anyway, it may work on Android too, who knows.
  • 8. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    The clients are desktop clients. Server is android. will try with the options you specified and will try to find out the problem.
  • 9. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    When i use the debug option the following is the output

    Allow unsafe renegotiation: false
    Allow legacy hello messages: true
    Is initial handshake: true
    Is secure renegotiation: false
    %% No cached client session
    *** ClientHello, TLSv1
    RandomCookie:  GMT: 1351552379 bytes = { 234, 161, 230, 34, 35, 20, 18, 115, 140, 247, 115, 111, 136, 85, 215, 7, 64, 211, 163, 199, 11, 252, 237, 91, 162, 192, 1, 34 }
    Session ID:  {}
    Cipher Suites: [SSL_DH_anon_WITH_RC4_128_MD5]
    Compression Methods:  { 0 }
    Extension renegotiation_info, renegotiated_connection: <empty>
    ***
    Thread-4, WRITE: TLSv1 Handshake, length = 52
    Thread-4, WRITE: SSLv2 client hello message, length = 47
    Thread-4, READ: TLSv1 Handshake, length = 81
    *** ServerHello, TLSv1
    RandomCookie:  GMT: 1351552135 bytes = { 3, 183, 206, 179, 43, 126, 162, 143, 87, 111, 159, 25, 156, 58, 252, 208, 180, 151, 63, 103, 195, 8, 108, 17, 196, 45, 238, 234 }
    Session ID:  {114, 196, 233, 92, 127, 7, 160, 103, 8, 254, 199, 15, 59, 191, 20, 170, 41, 82, 24, 32, 93, 28, 115, 198, 165, 171, 53, 197, 143, 55, 117, 26}
    Cipher Suite: SSL_DH_anon_WITH_RC4_128_MD5
    Compression Method: 0
    Extension renegotiation_info, renegotiated_connection: <empty>
    ***
    %% Created:  [Session-1, SSL_DH_anon_WITH_RC4_128_MD5]
    ** SSL_DH_anon_WITH_RC4_128_MD5
    Thread-4, READ: TLSv1 Handshake, length = 394
    *** Diffie-Hellman ServerKeyExchange
    DH Modulus:  { 190, 42, 59, 73, 202, 55, 64, 48, 138, 178, 251, 219, 118, 63, 29, 175, 168, 249, 192, 214, 189, 175, 225, 44, 195, 44, 82, 133, 13, 220, 201, 197, 92, 73, 7, 52, 106, 26, 176, 229, 190, 154, 209, 32, 160, 135, 77, 44, 14, 204, 117, 13, 29, 219, 116, 71, 72, 78, 148, 225, 9, 38, 85, 121, 158, 204, 238, 30, 119, 152, 47, 155, 15, 102, 5, 228, 121, 35, 42, 67, 58, 62, 128, 154, 6, 209, 169, 4, 154, 169, 33, 19, 210, 141, 172, 58, 251, 24, 145, 238, 15, 138, 105, 183, 198, 212, 68, 162, 33, 62, 86, 219, 207, 176, 8, 2, 3, 185, 113, 208, 128, 231, 68, 83, 188, 204, 76, 155 }
    DH Base:  { 122, 79, 91, 96, 241, 57, 93, 132, 32, 39, 139, 118, 35, 233, 95, 244, 73, 179, 154, 29, 12, 76, 24, 113, 43, 110, 217, 182, 118, 17, 92, 159, 194, 159, 126, 92, 146, 109, 108, 160, 19, 143, 150, 228, 25, 46, 249, 152, 141, 251, 120, 251, 73, 5, 84, 82, 58, 201, 49, 169, 0, 219, 100, 24, 80, 138, 168, 82, 210, 56, 1, 218, 32, 21, 215, 21, 24, 104, 167, 113, 200, 72, 225, 133, 6, 136, 44, 158, 58, 209, 158, 228, 154, 222, 224, 242, 80, 81, 250, 242, 180, 67, 234, 111, 197, 172, 85, 92, 181, 111, 174, 224, 37, 45, 64, 207, 47, 182, 14, 23, 34, 223, 3, 99, 47, 41, 114, 162 }
    Server DH Public Key:  { 157, 90, 36, 32, 109, 186, 117, 74, 233, 138, 117, 247, 57, 156, 95, 107, 176, 205, 89, 204, 251, 61, 6, 55, 131, 176, 215, 209, 118, 3, 126, 251, 108, 208, 144, 213, 251, 145, 57, 51, 180, 201, 157, 184, 54, 27, 213, 203, 208, 178, 22, 218, 229, 160, 31, 107, 172, 200, 116, 88, 149, 209, 25, 10, 44, 144, 159, 76, 191, 22, 86, 216, 182, 174, 174, 236, 154, 35, 231, 70, 118, 192, 17, 204, 132, 86, 140, 78, 242, 62, 5, 56, 144, 145, 26, 21, 33, 151, 95, 34, 174, 145, 96, 8, 44, 102, 193, 224, 118, 153, 211, 182, 70, 53, 156, 213, 243, 206, 106, 47, 98, 211, 138, 233, 77, 168, 61, 54 }
    Anonymous
    Thread-4, READ: TLSv1 Handshake, length = 4
    *** ServerHelloDone
    *** ClientKeyExchange, DH
    DH Public key:  { 142, 118, 253, 57, 10, 225, 36, 255, 92, 39, 120, 206, 118, 59, 163, 162, 218, 91, 178, 174, 16, 125, 88, 76, 57, 2, 116, 114, 125, 42, 126, 176, 71, 194, 149, 13, 209, 189, 218, 228, 203, 231, 0, 105, 107, 204, 42, 110, 166, 15, 147, 202, 214, 87, 225, 152, 44, 84, 223, 87, 77, 142, 71, 58, 220, 31, 229, 173, 99, 244, 24, 221, 125, 147, 166, 201, 219, 225, 95, 144, 24, 101, 78, 131, 215, 93, 98, 0, 222, 249, 191, 217, 50, 232, 255, 64, 16, 254, 216, 103, 96, 68, 88, 12, 61, 248, 81, 17, 207, 115, 24, 4, 192, 109, 20, 36, 20, 27, 116, 74, 24, 59, 240, 133, 187, 163, 84, 152 }
    Thread-4, WRITE: TLSv1 Handshake, length = 134
    SESSION KEYGEN:
    PreMaster Secret:
    0000: 3D 67 20 05 A2 40 13 0E   79 DC 53 46 36 F2 85 CA  =g ..@..y.SF6...
    0010: F9 9B 11 4C 12 DC C9 FC   DE CB 77 7D C1 8C 39 6F  ...L......w...9o
    0020: 66 94 29 BE 94 0B 27 A1   27 53 E4 0C BC 95 E1 CA  f.)...'.'S......
    0030: 64 78 29 24 6B 5E 47 53   94 8B BF 84 28 81 15 96  dx)$k^GS....(...
    0040: A0 28 7C 16 E2 73 D9 72   BF 5A 12 B4 85 92 64 7A  .(...s.r.Z....dz
    0050: 41 E9 DC E7 8A 93 B7 7E   81 16 F0 52 32 24 06 F8  A..........R2$..
    0060: 14 20 77 B7 6D 22 2C 65   F9 31 9D E3 B5 DE 1A FA  . w.m",e.1......
    0070: E3 64 AA 0D 6D EF A8 D1   21 4A 0E 21 07 8C 2C CD  .d..m...!J.!..,.
    CONNECTION KEYGEN:
    Client Nonce:
    0000: 51 8F 0D 7B EA A1 E6 22   23 14 12 73 8C F7 73 6F  Q......"#..s..so
    0010: 88 55 D7 07 40 D3 A3 C7   0B FC ED 5B A2 C0 01 22  .U..@......[..."
    Server Nonce:
    0000: 51 8F 0D 87 03 B7 CE B3   2B 7E A2 8F 57 6F 9F 19  Q.......+...Wo..
    0010: 9C 3A FC D0 B4 97 3F 67   C3 08 6C 11 C4 2D EE EA  .:....?g..l..-..
    Master Secret:
    0000: A4 6B 2C DC C0 F2 E9 B2   E8 09 2D 38 7A 1E FF AA  .k,.......-8z...
    0010: F3 A5 1E 71 24 C2 A7 34   1D 72 1B FB 63 39 0B 2A  ...q$..4.r..c9.*
    0020: E5 BE AB 72 18 80 71 59   D8 F7 BE 72 BB F1 1B 7D  ...r..qY...r....
    Client MAC write Secret:
    0000: 18 5C 16 58 1B A9 EB 79   B2 2B F5 48 94 1F FD 38  .\.X...y.+.H...8
    Server MAC write Secret:
    0000: A4 16 80 28 38 6B 7C AF   3B 72 60 10 12 44 3B 40  ...(8k..;r`..D;@
    Client write key:
    0000: EF 97 10 D1 97 C9 EE B3   75 90 03 E2 64 AA 9F 45  ........u...d..E
    Server write key:
    0000: 48 F4 58 03 C7 94 54 42   D5 09 9C 8F 7B 5E E0 4A  H.X...TB.....^.J
    ... no IV used for this cipher
    Thread-4, WRITE: TLSv1 Change Cipher Spec, length = 1
    *** Finished
    verify_data:  { 62, 6, 17, 211, 109, 223, 178, 100, 151, 192, 180, 110 }
    ***
    Thread-4, WRITE: TLSv1 Handshake, length = 32
    Thread-4, READ: TLSv1 Change Cipher Spec, length = 1
    Thread-4, READ: TLSv1 Handshake, length = 32
    *** Finished
    verify_data:  { 76, 46, 176, 38, 156, 50, 231, 188, 149, 175, 175, 148 }
    ***
    
    %% Cached client session: [Session-1, SSL_DH_anon_WITH_RC4_128_MD5]
    
    
    Thread-4, READ: TLSv1 Application Data, length = 18
    Thread-4, READ: TLSv1 Application Data, length = 18
    Thread-4, WRITE: TLSv1 Application Data, length = 20
    Thread-4, READ: TLSv1 Application Data, length = 17
    Thread-4, READ: TLSv1 Application Data, length = 17
    Thread-4, READ: TLSv1 Application Data, length = 45
    Thread-4, READ: TLSv1 Application Data, length = 24
    Thread-4, READ: TLSv1 Application Data, length = 17
    Thread-4, READ: TLSv1 Application Data, length = 18
    Thread-4, READ: TLSv1 Application Data, length = 17
    Thread-4, READ: TLSv1 Application Data, length = 17
    Finalizer, called close()
    Finalizer, called closeInternal(true)
    Thread-5, WRITE: TLSv1 Application Data, length = 139
    Thread-5, WRITE: TLSv1 Application Data, length = 86
    Thread-5, WRITE: TLSv1 Application Data, length = 18
    Thread-5, WRITE: TLSv1 Application Data, length = 24
    Thread-5, WRITE: TLSv1 Application Data, length = 17
    Thread-5, WRITE: TLSv1 Application Data, length = 34
    {code}
    In the above output "*%% Cached client session: [Session-1, SSL_DH_anon_WITH_RC4_128_MD5]*" step is taking time. What could be the reason? I mean after printing this message it is taking time.
    
    Edited by: Muralidhar on May 12, 2013 9:10 AM
    
    Edited by: Muralidhar on May 12, 2013 9:11 AM
    
    Edited by: Muralidhar on May 12, 2013 9:13 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  • 10. Re: socket.getOutputStream getting blocked for significant amount of time?
    EJP Guru
    Currently Being Moderated
    The handshake is finished at that point. It looks like there was simply nothing to read during the gap.

    Why are you creating an ObjectInputStream and never reading from it?
  • 11. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    On the server code even without getting the "outputStream" what can be written?

    No that is not the case. This is only part of the code. I saw problem in getting "s.outputstream()" so i have only posted that part of the code.

    Edited by: Muralidhar on May 12, 2013 9:26 AM
  • 12. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    Even I tried in many other ways. Finally i found
    OutputStream out=s.getOutputStream();
    this is taking time. Significant amount of time. I am not sure how to resolve this.
  • 13. Re: socket.getOutputStream getting blocked for significant amount of time?
    EJP Guru
    Currently Being Moderated
    Well you can see for yourself that the last thing before the gap is the session information, then the next thing is a read. But your code starts with a write. So there is already something odd about this. Does the SSL trace come from the same end that is executing that code?
  • 14. Re: socket.getOutputStream getting blocked for significant amount of time?
    Murray9654 Newbie
    Currently Being Moderated
    EJP wrote:
    Well you can see for yourself that the last thing before the gap is the session information, then the next thing is a read. But your code starts with a write. So there is already something odd about this. Does the SSL trace come from the same end that is executing that code?
    yes. i have started the client(desktop) with the given debug option. the traces were from the client when i connected to android server.

    The following is the corresponding client code:-
                            SSLSocket socket= (SSLSocket)sslsf.createSocket(ip,Constants.CHAT_SERVER_PORT);
                   final String[] enabledCipherSuites = { "SSL_DH_anon_WITH_RC4_128_MD5" };
                   socket.setEnabledCipherSuites(enabledCipherSuites);               
                   InputStream in=socket.getInputStream();          
                   OutputStream out=socket.getOutputStream();               
                   ObjectInputStream ois=new ObjectInputStream(in);               
                   ObjectOutputStream oos=new ObjectOutputStream(out);               
                   Object obj=ois.readObject();                    
                   SocketInfo sockInfo=new SocketInfo(socket,oos,ois,ip);
                   
    The client code behaves as expected. On the client side it gets blocked on
    ObjectInputStream ois=new ObjectInputStream(in);
    This is expected. This gets blocked until the corresponding
     ObjectOutputStream
    flushes. This is getting unblocked when the code
    OutputStream out=s.getOutputStream();
    on the server gets unblocked and the OjectOutputStream flushes.

    I am not sure why
    OutputStream out=s.getOutputStream();
    this is getting blocked on android.

    Edited by: Muralidhar on May 12, 2013 11:06 AM

    Edited by: Muralidhar on May 12, 2013 11:06 AM

    Edited by: Muralidhar on May 12, 2013 11:11 AM

    Edited by: Muralidhar on May 12, 2013 11:20 AM

    Edited by: Muralidhar on May 12, 2013 11:33 AM
1 2 3 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points