line_delimiter option in gen_tcp

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

line_delimiter option in gen_tcp

Peter Devoy
Hi list

TL;DR: can gen_tcp packets be terminated by null byte? 

A few years ago I was looking at erlang for a pet project -- an XML socket server for an old multiplayer Flash game.

The XML packets are terminated by null bytes and I swear I had gen_tcp configured and working with {packet, line} and {line_delimiter, \00}.

Only now I can't find the code and gen_tcp does not appear to have a documented or undocumented line_delimiter option. I can only find that option referenced in inet.

Am I imagening the whole thing? Is there some way to achieve packet delimitation by null byte using gen_tcp?

I am an erlang noob so any help would be much appreciated! 

Cheers


Pete


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: line_delimiter option in gen_tcp

Leonard Boyce-2
Hi Pete,

Maybe you're looking for inet:set_opts/2 ?

Leonard

On Thu, Oct 17, 2019 at 11:51 AM Peter Devoy <[hidden email]> wrote:
Hi list

TL;DR: can gen_tcp packets be terminated by null byte? 

A few years ago I was looking at erlang for a pet project -- an XML socket server for an old multiplayer Flash game.

The XML packets are terminated by null bytes and I swear I had gen_tcp configured and working with {packet, line} and {line_delimiter, \00}.

Only now I can't find the code and gen_tcp does not appear to have a documented or undocumented line_delimiter option. I can only find that option referenced in inet.

Am I imagening the whole thing? Is there some way to achieve packet delimitation by null byte using gen_tcp?

I am an erlang noob so any help would be much appreciated! 

Cheers


Pete

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: line_delimiter option in gen_tcp

Peter Devoy
Hi Scott, Leonard,

Thanks for your help.  I have now experimented further with inet:setopts/2 and, 
although it feels like it should work, it still is not behaving as I would expect.

I am going to try and write the most simple programme possible that
exemplifies the behaviour and post it on StackOverflow and/or here if it still
doesn't work as expected.

Kind regards


Pete

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: line_delimiter option in gen_tcp

Peter Devoy
Hi list

Figured it out.  For completeness and reference, my mistakes were two-fold:

1) Setting options on Listen socket instead of Accept socket.
2) Did not pattern match for "ok" on inet:setopts/2 so didn't realise typing was
strict:
inet:setopts(AcceptSocket, [{line_delimiter, [0]}]).  %fails
inet:setopts(AcceptSocket, [{line_delimiter, "\0"}]). %fails

Eventually I got it to work with char notation but not before this mistake:
inet:setopts(AcceptSocket, [{line_delimiter, $0}]).   %ascii numeral 0 (fails)
inet:setopts(AcceptSocket, [{line_delimiter, $\0}]).  %ascii NUL (works!)

Final proof:

Thanks again


Pete





_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions