Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Protocols and Servers  RSS feed

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a bit confuse about the handling of request and response by the server on HTTP Protocol.

Earlier i believed that whenever there is some request generated to server, the server maintain some data structure in itself, having all the request information (ip address etc) and then using that DATA STRUCTURE info, the server sends back the response.

But, yesterday one of my senior told me that actually the pipe from which your server get the request stream is remained open and server write back to that pipe stream.

From my senior's statement, i am confuse. HTTP is stateless protocol, then does his statement is correct? ...

What your knowledge say ... ? How server respond to the request, does it get information to something store within server for response or it keeps that pipe stream open to write the response?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One definition of a connection oriented protocol is that the server and client retain some information about each other which can be used in future conversation exchanges. HTTP is connectionless and sessionless. An HTTP server accepts a request, does some processing and writes a response, period. An HTTP server written in Java does a ServerSocket.accept() to get a new Socket, reads from the socket, writes to the socket and closes the socket. The HTTP server doesn't remember anything about the client or previous requests.

Most web server products build their own connection and session structures on top of HTTP, so you'll see session info in a servlet container or a Microsoft IIS server. All that is outside the HTTP spec, in the Servlet spec or IIS or whatever server you find.

It's confusing to see methods like URL getConnection and socket connect. Those are operating at lower network protocols like TCP. TCP is connection oriented; the HTTP layer makes a TCP connection for each HTTP request and closes it immediately after.

In recent years the HTTP spec allows HTTP partners to keep their TCP connections for a short time just in case the client makes another request to the same server. This happens a lot when a browser downloads a web page and a bunch of images from the same site. But it's a hidden connection layer; you can't see the workings from your code at either end.

Did that make things better or worse?
[ July 15, 2007: Message edited by: Stan James ]
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Things are bit clear now, but a new confusion is created.

Just want to clear one thing ... you wrote

ServerSocket.accept() to get a new Socket, reads from the socket, writes to the socket and closes the socket ...

what do you mean "writes to the socket" ... does it mean that server write the response to the socket and the closes it?

Can you give me some authentic links from where i can read and can discuss all this with my senior?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, the Socket that comes back from ServerSocket.accept() has input and output streams. The server reads the request and writes the response on those streams. The Socket chapter of theSun Network Tutorial has good examples of a socket server. An HTTP server starts out like this and adds a ton of protocol handling ... formatting the HTTP headers and body per the standards. If you look at the W3C standards you'll see that implementing an HTTP server is a pretty big job.
[ July 15, 2007: Message edited by: Stan James ]
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Stan. your explanation was quite helpful

one more question. Not related to this discussion. I want to take part in some open source project to increase my knowledge. Can you guide me to some nice forums where i can read the discussions?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!