Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is TCP protocol stateless?

Tags:

HTTP,the protocol residing over TCP protocol is stateless and also the IP protocol is stateless But how can we conclude that TCP is stateless or not?

like image 686
tourist Avatar asked Nov 11 '13 05:11

tourist


People also ask

Is the TCP connection stateful or stateless?

The TCP protocol is a stateful protocol because of what it is, not because it is used over IP or because HTTP is built on top of it.

Is TCP or UDP stateless?

User Datagram Protocol (UDP) is also located in the transport layer of OSI model along with TCP. But unlike TCP, UDP is stateless. This is because, UDP doesn't wait for a connection, doesn't have error recovery and do not re-transmit failed packets. It doesn't require a state to maintain track of the transmission.

Which protocol is stateless?

The HTTP protocol is a stateless one. This means that every HTTP request the server receives is independent and does not relate to requests that came prior to it.

Is UDP stateless?

Stateless Protocol: HTTP (Hypertext Transfer Protocol), UDP (User Datagram Protocol), DNS (Domain Name System) are the example of Stateless Protocol.


2 Answers

You can't assume that any stacked protocol is stateful or stateless just looking at the other protocols on the stack. Stateful protocols can be built on top of stateless protocols and stateless protocols can be built on top of stateful protocols. One of the points of a layered network model is that the kind of relationship you're looking for (statefulness of any given protocol in function of the protocols it's used in conjunction with) does not exist.

The TCP protocol is a stateful protocol because of what it is, not because it is used over IP or because HTTP is built on top of it. TCP maintains state in the form of a window size (endpoints tell each other how much data they're ready to receive) and packet order (endpoints must confirm to each other when they receive a packet from the other). This state (how much bytes the other guy can receive, and whether or not he did receive the last packet) allows TCP to be reliable even over inherently non-reliable protocols. Therefore, TCP is a stateful protocol because it needs state to be useful.

I would also like to point out that while HTTP and HTTPS (which is just HTTP over SSL/TLS, really) are essentially stateless (each request is a valid standalone request per the protocol), applications built on top of HTTP and HTTPS aren't necessarily stateless. For instance, a website can require you to visit a login page before sending a message. Even though the request where the client sends a message is a valid standalone request, the application will not accept it unless the client authenticated herself before. This means that the application implements state over HTTP.

On a side note, the statefulness of HTTP can be somewhat confusing, as several applications (on a clearly different OSI layer) will leak their state to HTTP. For instance, if a user tries to view a blog post that doesn't exist, the blog application might send back a response with the 404 status code, even though the file handling the blog post search itself was found.

like image 109
zneak Avatar answered Oct 04 '22 20:10

zneak


Zneak is correct that you can use any communication for stateful purposes, but the question being asked is whether the protocol itself is stateful.

Wikipedia:

In computing, a stateless protocol is a communications protocol that treats each request as an independent transaction that is unrelated to any previous request so that the communication consists of independent pairs of requests and responses. A stateless protocol does not require the server to retain session information or status about each communications partner for the duration of multiple requests. In contrast, a protocol which requires keeping of the internal state on the server is known as a stateful protocol.

To apply this definition, first we must understand what a "request" is.

  • IP - an IP packet
  • TCP - a TCP packet
  • HTTP - an HTTP request/response

That would make TCP a stateful protocal, since parties must remember what state the other is in, and what bytes the other has. Hence the TCP state diagram.

like image 43
Paul Draper Avatar answered Oct 04 '22 20:10

Paul Draper