3

I'm looking for the actual code implementation of connect() & disconnect() in java.net.URLConnection.java & java.net.HttpURLConnection.java.

@ In the following link, Where is connect() and disconnect() implemented? Martin Hansen answered that several implementations are out there such as AbstractDelegateHttpsURLConnection. (Further search, com.squareup.okhttp.internal.http.HttpURLConnectionImpl)

I want to know which implementation of HttpURLConnection is used in Android to connect to and disconnect from the server via HTTP.

Community
  • 1
  • 1
  • That answer will vary by Android OS release, most likely. OkHttp has been used since 4.4 or thereabouts, IIRC. – CommonsWare Dec 08 '15 at 23:27
  • 1
    The full OkHttp is not. However, Google switched to using OkHttp's code for `HttpUrlConnection`, specifically for its SPDY support. – CommonsWare Dec 08 '15 at 23:37
  • But `okhttp` library is not included in default Android setting. BTW, I'm targeting 5.0 and above but doesn't matter. I want to know how the actual interaction between Http and TCP is made. ex. if I call `connect()` then it should be delivered to the kernel to establish TCP session. I want to know the step-by-step classes and methods that are involved in the above process. – Sooyoung Jang Dec 08 '15 at 23:43
  • 1
    "But okhttp library is not included in default Android setting" -- see my second comment above. "I want to know the step-by-step classes and methods that are involved in the above process" -- check out the source code for every Android major/minor/patchlevel version from 5.0 onwards, then trace through the code. Of course, please bear in mind that you do not have access to the modifications to Android made by device manufacturers, which may change "the step-by-step classes and methods that are involved in the above process" for those manufacturers' devices. – CommonsWare Dec 08 '15 at 23:47
  • I want to know which source code to check. For example, I just need to call `HttpURLConnection con = (HttpURLConnection) url.openConnection();` `con.connect();` to connect to a server. Which code should I check to know what's going on underneath? – Sooyoung Jang Dec 09 '15 at 00:48
  • I'd start with `HttpURLConnection` and `URL`, and work from there. – CommonsWare Dec 09 '15 at 00:49
  • For example, the [latest source for `URL`](https://android.googlesource.com/platform/libcore/+/refs/heads/master/luni/src/main/java/java/net/URL.java) shows that `openConnection()` delegates its work to `streamHandler`, which is an instance of `URLStreamHandler`, and so on. – CommonsWare Dec 09 '15 at 00:54
  • I've followed `HttpURLConnection`, `URLConnection`, `URL`, `SocketOptions`, `SocketImpl`, `AbstractPlainSocketImpl`, `PlainSocketImpl`, and `URLStreamHandler` and so on.... But I ended with abstract method with no code. – Sooyoung Jang Dec 09 '15 at 01:22
  • @ `abstract public void connect() throws IOException;` @ `public abstract void disconnect();` @ `abstract void socketConnect(InetAddress address, int port, int timeout) throws IOException;` ..... – Sooyoung Jang Dec 09 '15 at 01:23
  • I've been working with this for over a day.... Looked at android.jar, jdk1.8.0_25...all the code that are related to http, url. But I could only find abstract method in the end. I want to know where is the code that actually calls kernel to open TCP session? – Sooyoung Jang Dec 09 '15 at 01:27

0 Answers0