:gen_tcp read until

Is there a way to read off a socket until certain characters are reached? I want something like packet: :line where the stop character can get changed from \n to something else.

Is that possible with gen_tcp?

That is the ol’ Erlang {line_delimiter, Char} option, so in Elixir that would be line_delimiter: ?j or so if you wanted the ‘j’ character to be the delimiter as an example, if I remember correctly (been a while since I’ve implemented a low-level tcp protocol in erlang, been using higher level things for a while now).

Reference: Erlang -- inet

1 Like

thank you!

1 Like