HttpUrlConnection, URLConnection, and Sockets for HTTP

Suppose we want to send requests and receive documents over HTTP frequently. Is establishing direct connections and manually sending HTTP request by using Sockets faster than simply using a HttpUrlConnection instance?

What if we want to establish persistent connections (HTTP Keep-Alive) ?

[302 byte] By [Arash.Shahkara] at [2007-11-27 7:51:53]
# 1

The time to transfer data over a socket or an HttpUrlConnection will be the same, since your bandwidth will be the bottleneck, not the client application. To instantiate a connection, again, I would imagine that the time to send the headers, etc... are going to take much longer (but will still happen very quickly) than to create any object in your program.

In other words, I highly doubt that using raw sockets will help, since your HTTP-ified sockets will be like HttpURLConnections anyway, and any small discrepancies in speed will be insignificant.

RATiXa at 2007-7-12 19:33:05 > top of Java-index,Core,Core APIs...
# 2
Using raw sockets is probably slower than using HttpURLConnection, which runs a connection pool.
ejpa at 2007-7-12 19:33:05 > top of Java-index,Core,Core APIs...
# 3

> Using raw sockets is probably slower than

> using HttpURLConnection, which runs a connection pool.

Thanks for the tip.

I searched the web for "Connection Pool" and read the first 4-5 results. As I understood, connection pools are a group of cached connections which resides on the server side in the database server or application server memory. Unfortunately I don't understand how HttpURLConnection runs a connection pool, or perhaps I didn't understand what a Connection pool really is! Would you please explain more?

Arash.Shahkara at 2007-7-12 19:33:05 > top of Java-index,Core,Core APIs...
# 4
In this case the connection pool resides at the client. It is the client-side implementation of the Connection: keep-alive header.RMI also runs a client-side connection pool so your definition is too specific.
ejpa at 2007-7-12 19:33:05 > top of Java-index,Core,Core APIs...