Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is HTTP protocol stateless if it can deal with persistent connections?

Tags:

http

The HTTP protocol is stateless, but I found this on the Kurose-Ross book:

The default HTTP method is with persistent connections and pipeling.  

This means that it can handle multiple requests, so it keeps opened the socket of a client that wants to ask multiple requests.Is that true? If yes, why is HTTP protocol considered stateless?

like image 370
Ramy Al Zuhouri Avatar asked Nov 05 '12 11:11

Ramy Al Zuhouri


People also ask

Why is the HTTP protocol considered to be a stateless protocol?

HTTP is called as a stateless protocol because each request is executed independently, without any knowledge of the requests that were executed before it, which means once the transaction ends the connection between the browser and the server is also lost.

Is persistent HTTP stateless?

Therefore, HTTP is called a stateless protocol. HTTP can use both nonpersistent connections and persistent connections. A nonpersistent connection is the one that is closed after the server sends the requested object to the client. In other words, the connection is used exactly for one request and one response.

How HTTP with persistent connection is different than the HTTP with non-persistent connection?

This case stands for a single object transmission. After the client receives the object in non-persistent, the connection is immediately closed. This is the basic difference between persistent and non-persistent. The persistent connection ensures the transfer of ​multiple objects over a single connection.

Can HTTP connections be persistent?

HTTP has a persistent connection function that allows the channel to remain open rather than be closed after a requested exchange of data. TCP is a connection-oriented protocol: It starts a connection after confirmation from both ends that they are available and open to a data exchange.


1 Answers

HTTP persistent connections relate to TCP connection being left open. HTTP operates on top of TCP - so TCP can be connected and/or stateful whereas HTTP would not. TCP is just the transport for HTTP.

If you look at the OSI model, you can see that TCP is on layer 4 (transport), whereas HTTP is on layer 7 (application). HTTP is not tied to TCP and could use other ways of transport too - as a protocol, it is not "inheriting" features from TCP.

(Note also that the persistent connection is not really persistent for a very long time. For Apache 2, it is open only for 5 seconds per default, and "According to RFC 2616 (page 46), a single-user client should not maintain more than 2 connections with any server or proxy".)

like image 54
eis Avatar answered Nov 02 '22 23:11

eis