Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

SSLSocket BufferedReader blocking problem

Thread view: 
sean.antony@gmail.com - 06 Mar 2007 20:57 GMT
I have a client program which connects to an Apache server, sends some
HTTP messages and retrieves the responses.

An example message is:

OPTIONS / HTTP/1.1
Host: 127.0.0.1
Accept: */*

The response from Apache is:

HTTP/1.1 200 OK
Date: Wed, 07 Mar 2007 14:57:16 GMT
Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.8a DAV/2
DAV: 1,2
DAV: <http://apache.org/dav/propset/fs/1>
MS-Author-Via: DAV
Allow:
OPTIONS,GET,HEAD,POST,DELETE,TRACE,PROPFIND,PROPPATCH,COPY,MOVE,LOCK,UNLOCK
Content-Length: 0
Content-Type: httpd/unix-directory

This is the code that gets the response from Apache, the in variable
is a BufferedReader connected to the InputStream of the SSLSocket.

private String getResponse() throws IOException {
    String response = "";
    int c = in.read();
    char ch;
    long start = System.currentTimeMillis();
    while (in.ready() && c != -1) {
        ch = (char) c;
        response += ch;
        c = in.read();
    }
    long finish = System.currentTimeMillis();
    System.out.println(finish - start);
    ch = (char) c;
    response += ch;
    return response;
}

The output to the console is how long it took to get the whole message
from the InputStream. In HTTP (Socket) mode this number is between
0-20 milliseconds but when i use HTTPS (SSLSocket) mode it is approx
5000! This number is independent of the time it takes to handshake
with the server.

In SSL mode the above method fails actually, because in.ready()
returns false the first time, instead i have to modify it to:

while ((c = in.read()) != -1) {
    ch = (char) c;
    response += ch;
    System.out.print(ch);
}

In which case, i get the whole message printed to the console as fast
as HTTP mode but on the final evaluation of in.read() it takes the
previously stated 5000 ms to finally exit the loop and return the
String response.

I am certain my Apache server is configured correctly as if i use a
web browser to navigate the site in HTTPS the response is instant as
like in unsecure HTTP mode.

So why am i seeing this 5000 ms delay, when i reach the end of the
stream in the BufferedReader?

There should be no difference in reading the BufferedReader when using
either HTTP or HTTPS mode, given that i've accounted for the time it
takes to handshake, right?
sean.antony@gmail.com - 07 Mar 2007 01:08 GMT
> I have a client program which connects to an Apache server, sends some
> HTTP messages and retrieves the responses.
[quoted text clipped - 70 lines]
> either HTTP or HTTPS mode, given that i've accounted for the time it
> takes to handshake, right?

Solution found at http://forum.java.sun.com/thread.jspa?messageID=9537105

Case closed.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.