1

I have an erlang gen_fsm process that talks to a remote server via tcp using erlang's built-in gen_tcp.

I would like to make this a web-socket client. Upon some investigation, I got this erlang websocket client library Erlang Websocket client.

looking at some examples, it looks like I have to use the

-behaviour(websocket_client_handler).

Basically, I do this in my start_link

start_link(UserID) ->
   gen_fsm:start_link(?MODULE, [UserID], []).

However, the other behavior expects a different return values for the init and a different state. I already have a state for my gen_fsm.

Can someone throw some context around this.

I think it is nothing wrong in having two behaviors defined for the same module but given that each behavior requires different return types in the init/[1/2] functions, I start to think if this is really something feasible. Just wanted to reach out to someone experienced.

Thanks.

sad
  • 820
  • 1
  • 9
  • 16

1 Answers1

1

In principle, I don't think it's a problem: init/1 and init/2 are two completely different functions, gen_fsm:start_link will only call init/1 and websocket_client:start_link will only call init/2. And of course, the state from gen_fsm's callbacks won't be passed to websocket_client's, so they can be completely different. In practice, I'd expect it to be really confusing.

Instead, I'd separate the websocket client into a separate module which is called from the gen_fsm (if I understood you correctly).

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487