开发者

Arguments for stateless protocols (context: simple point-to-point communication)

(So this question has been asked before, but in a general sense, and most of the responses were in the context of general network communications with multiple servers/clients/etc.)

In the context of a simple point-to-point communications protocol, what are the advantages/disadvantages of stateful and stateless protocols? My instinct is that stateless is better (given much exposure to HTTP) with simple command-response packets, but I'm not sure why. I am also working with a supervisor who has had much experience using stateful protocols with sequen开发者_Python百科ce numbers, connection establishing methods, etc. and he keeps encouraging me to use a stateful protocol. We are at a bit of an impasse and can't seem to convince each other of the right approach.

Another question about simple point-to-point communications protocols brought up some good examples, namely HDLC (stateful) and MODBUS (stateless).


If you look at the protocol from a conversational viewpoint, that might make it easier.

In a stateless protocol, there is no "Hello" or "Goodbye". Each request is simply "Give me that", "Take this", or the like, and each request stands on it's own. If the client gives the server something, it doesn't care what the server does with it. If the client needs to know about what it just gave the server, then it will ask for it again to verify.

This (statelessness) sounds good and it is good for two independent processes (server and the client) particularly if they are loosely coupled.

But if there are two cooperating processes, where the two tasks are dependent on each other and one needs the output of the other for them both to be successful, then statelessness adds overhead since each communication and action needs to be verified with questions. Or there needs to be a body of context shared between the two.

Think of a surgeon and her assistant handing her tools. The surgeon says "scapel" and she knows the communication was completed when she get's the scalpel placed in her hand. The "stateful" assistant can track the state of the communication and know that after the "scapel" will come the "suction" or "retractor" command, and be ready with the proper instrument. So the conversation has a state - a beginning and an end - "hello" and "goodbye". This is good, because it reduces latency and makes the communication overhead lower.

You could make the Surgeon/Assistant protocol stateless - but would that affect quality in terms of the overall outcome?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜