📜  无状态和有状态协议之间的区别

📅  最后修改于: 2021-09-27 15:05:51             🧑  作者: Mango

Web 浏览器和服务器的网络协议分为两种类型:无状态协议和有状态协议。

这两种协议是根据服务器或服务器端软件保存状态或会话信息的要求来区分的。

1.无状态协议:
无状态协议是一种网络协议,其中客户端根据当前状态向服务器发送请求并返回服务器响应。它不需要服务器为多个请求保留会话信息或每个通信伙伴的状态。

HTTP(超文本传输协议)、UDP(用户数据报协议)、DNS(域名系统)都是无状态协议的例子。

无状态协议的静默功能:

  • 无状态协议简化了服务器的设计。
  • 无状态协议需要较少的资源,因为系统不需要跟踪多链路通信和会话细节。
  • 在无状态协议中,每个信息包都自行传输,无需参考任何其他数据包。
  • 无状态协议中的每个通信都是离散的,与之前或之后的通信无关。

2. 有状态协议:
在有状态协议中如果客户端向服务器发送请求,那么它期待某种响应,如果它没有得到任何响应,则它重新发送请求。 FTP(文件传输协议)、Telnet 是有状态协议的例子。
有状态协议的静默功能:

  • 状态协议通过跟踪连接信息为客户端提供更好的性能。
  • 有状态应用程序需要后备存储。
  • 有状态的请求总是依赖于服务器端的状态。
  • TCP 会话遵循有状态协议,因为两个系统都在其生命周期内维护有关会话本身的信息。

无状态和有状态协议的比较:

Stateless Protocol Stateful Protocol
Stateless Protocol does not require the server to retain the server information or session details. Stateful Protocol require server to save the status and session information.
In Stateless Protocol, there is no tight dependency between server and client. In Stateful protocol, there is tight dependency between server and client
The Stateless protocol design simplify the server design. The Stateful protocol design makes the design of server very complex and heavy.
Stateless Protocols works better at the time of crash because there is no state that must be restored, a failed server can simply restart after a crash. Stateful Protocol does not work better at the time of crash because stateful server have to keep the information of the status and session details of the internal states.
Stateless Protocols handle the transaction very fastly. Stateful Protocols handle the transaction very slowly.
Stateless Protocols are easy to implement in Internet. Stateful protocols are logically heavy to implement in Internet.