[erlang-questions] tcp data in a gen_fsm

Frans Schneider schneider@REDACTED
Mon Nov 30 08:41:36 CET 2015


For me, implementing the protocol as a gen_fsm feels very natural. Since 
the unpacking of my data involves splitting the raw data stream in 
proper chunks, conditionally decrypting these chunks with a stream 
cypher and lastly decoding them into stanzas according to some mutilated 
protocol scheme, I think I will use a stack of processes, each specific 
for the task at hand. Having modules / processes dealing with one 
particular task feels rather good.

Thanks for all the input, which is a great help to me.

/Frans

On 11/30/2015 08:12 AM, Max Lapshin wrote:
> We have fully refused from using gen_fsm and especially in handling 
> protocol states in gen_fsm.
>
> Everywhere we use something like:
>
> handle_info({tcp, Socket, Input},  #state{protocol_state = S0} = State) ->
>    {ok, OutputCommands, S1} = some_protocol:handle(Input, S0),
>    ..handle somehow OutputCommands
>   inet:setopts(Socket, [{active,once}]),
>   {noreply, State#state{protocol_state = S1}}.
>
>
> Such approach allows to record Input to file and write a test for 
> output commands. Also it allows more easily handle situation when 
> there is more than 1 command in Input packet.
>
>




More information about the erlang-questions mailing list