Design patterns for network protocols?

守給你的承諾、 提交于 2020-01-14 04:09:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/21801110/design-patterns-for-network-protocols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!