After checking out Gen_Fsm and Gen_Server documents, I found that, more or less, they act as similar behavior. In my opinion, if there is one loop function for sending broadcast or listening tcp sock, it is better to use Gen_Fsm, or else to use gen_server. i want to know whether it is right ?
After checking out Gen_Fsm and Gen_Server documents, I found that, more or less, they
Share
You have seen right that
gen_serverandgen_fsmare very similar in functionality.However in most programs there is much more
gen_serverthangen_fsmusage.In my opinion
gen_fsmis only useful when the usage 100% fits the gen_fsm model. So there has to be a simple and clear finite state machine that fits to your problem. Be aware that usually FSM’s state count tends to explode in the face of the real world.If you find yourself having lots of secondary state information in
gen_fsm‘sStatevariable its probably time to switch togen_serverand addgen_fsm‘ s state to theStatevariable.Generally when in doubt: use
gen_serverOne disadvantage of both
gen_serverandgen_fsm(which comes out worse ingen_fsmusually) is that you can’t use selective receive. Selective receive is a important tool for reducing state machine complexity in real world applications.To have the advantage of both selective receive and OTP behaviours I’d recommend plain_fsm.