What are the most frequently used flow controls for handling protocol communication? - TagMerge
3What are the most frequently used flow controls for handling protocol communication?What are the most frequently used flow controls for handling protocol communication?

What are the most frequently used flow controls for handling protocol communication?

Asked 1 years ago
1
3 answers

It sounds like the "while + switch/case" is a statemachine implementation. I believe that a well thought out statemachine is often the easiest and most readable way to implement a protocol.

When it comes to statemachines, breaking some of the traditional programming rules comes with the territory. Rules like "every function should be less than 25 lines" just don't work. One might even argue that statemachines are GOTOs in disguise.

Source: link

0

For cases where you key off of a field in a protocol header to direct you to the next stage of processing for that protocol, arrays of function pointers can be used. You use the value from the protocol header to index into the array and call the function for that protocol.

You must handle all possible values in this array, even those which are not valid. Eventually you will get a packet containing the invalid value, either because someone is trying an attack or because a future rev of the protocol adds new values.

Source: link

0

If it is all one protocol being handled then a switch/case statement may be your best bet. However you should break all the individual message handlers into their own functions.

If your switch statement contains any code to actually handle the messages than you would be better off breaking them out.

If it is handling multiple similar protocols you could create a class to handle each one based off the same abstract class and when the connection comes in you could determine which protocol it is and create an instance of the appropriate handler class to decode and handle the communications.

Source: link

Recent Questions on c

    Programming Languages