且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无状态和状态完整协议之间的区别。无状态和有状态协议的示例

更新时间:2023-01-14 08:06:01

参见: asp.net mvc - 有状态和无状态之间的区别是什么? - 程序员堆栈交换 [ ^ ]。


Http is inherently stateless. So state must be built into your applications

Stateless - There's no memory (state) that's maintained by the program

Stateful - The program has a memory (state)

To illustrate the concept of state I'll define a function which is stateful and one which is stateless

Stateless

//The state is derived by what is passed into the function

function int addOne(int number)
{
    return number + 1;
}
Stateful

//The state is maintained by the function

private int _number = 0; //initially zero 

function int addOne()
{
    _number++;
    return _number;
}