Object-oriented networking

后端 未结 7 1316
臣服心动
臣服心动 2021-02-05 11:07

I\'ve written a number of networking systems and have a good idea of how networking works. However I always end up having a packet receive function which is a giant switch stat

7条回答
  •  遇见更好的自我
    2021-02-05 11:29

    A more OO way to handle this is to build a state machine using the state pattern.

    Handling incoming raw data is parsing where state machines provide an elegant solution (you will have to choose between elegant and performance)

    You have a data buffer to process, each state has a handle buffer method that parses and processes his part of the buffer (if already possible) and sets the next state based on the content.

    If you want to go for performance, you still can use a state machine, but leave out the OO part.

提交回复
热议问题