[英]Design patterns for network protocols?
So I'm building a fairly simple file transfer server/client but having a hard time to figure out a good design for processing different commands and states within the protocol.. 因此,我正在构建一个相当简单的文件传输服务器/客户端,但是很难找到一个好的设计来处理协议中的不同命令和状态。
Say that you have 3 different commands upload
, remove
, download
, you could use 3 different if-statements and keep track of states with additional if-statements, but that wont scale and will be impossible to maintain.. 假设您有3个不同的命令
upload
, remove
, download
,则可以使用3个不同的if语句,并使用其他if语句来跟踪状态,但是不会扩展,将无法维护。
The Chain Of Responsibility design pattern could be used for sequential stuff such as encryption and compression, but it wont take care of the logic for commands. 责任链设计模式可以用于顺序工作,例如加密和压缩,但不会考虑命令的逻辑。
I know that this is a quite broad question, but does anyone have any suggestions? 我知道这是一个相当广泛的问题,但是有人有什么建议吗?
The following may be helpful: 以下内容可能会有所帮助:
To provide different implementations for the same operation based on some conditions: http://en.wikipedia.org/wiki/Strategy_pattern 根据某些条件为同一操作提供不同的实现: http : //en.wikipedia.org/wiki/Strategy_pattern
To maintain state of the communication (eg the current protocol command): http://en.wikipedia.org/wiki/State_pattern 维护通信状态(例如当前协议命令): http : //en.wikipedia.org/wiki/State_pattern
For security/compression: http://en.wikipedia.org/wiki/Decorator_pattern or Chain-of-responsibility 为了安全/压缩: http : //en.wikipedia.org/wiki/Decorator_pattern或责任链
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.