网络协议的设计模式? [英] Design patterns for network protocols?

查看:148
本文介绍了网络协议的设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在构建一个相当简单的文件传输服务器/客户端,但是很难找出一个很好的设计来处理协议中的不同命令和状态。



说你有3个不同的命令上传删除下载,你可以使用3个不同的if语句,并用额外的if语句跟踪状态,但是不会缩放,并且将不可能维护..



责任链设计模式可用于诸如加密和压缩之类的顺序内容,但它不会处理命令的逻辑。



我知道这是一个相当广泛的问题,但有人有任何建议吗?

解决方案

以下可能有帮助:



根据一些条件为相同的操作提供不同的实现: http://en.wikipedia.org/wiki/Strategy_pattern



保持通信状态(例如,当前协议命令): http://en.wikipedia.org/wiki/State_pattern



对于安全/压缩: http://en.wikipedia .org / wiki / Decorator_pattern 或链责任


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..

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

To maintain state of the communication (e.g. the current protocol command): http://en.wikipedia.org/wiki/State_pattern

For security/compression: http://en.wikipedia.org/wiki/Decorator_pattern or Chain-of-responsibility

这篇关于网络协议的设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆