Friday, August 14, 2009

Http - hummm

Http is a neat and clean protocol. It's beauty lies in it's simplicity. I am pretty sure so many of us must have built many applications based on this http. It's so part of our life that we don't realize that when we type a URL in browser and hit enter. Browser acts as a client and opens up a TCP/IP connection with the server. For this discussion let's assume server is tomcat as it is completely written in Java. When we start the tomcat using batch file, actually we are instantiating an instance of JVM. We have a server socket at port 8080 which waits for clients to create a connection.

ServerSocket serverSocket = new ServerSocket(8080);

Socket socket = serverSocket.accept;

So when we type a URL and hot enter. The server returns an instance of socket. In java this will a TCP/IP socket. Server Socket / Socket saves us from the internals of TCP/IP. Now tomcat can simply use this socket to read the request.

A simple http request would be of the following format.

No comments: