favetelinguis
Making a ssl socket smart about terminating char in messages
I have an ssl socket which receives messages in JSON format. Right now im using Erlang ssl to setup the connection. In my implementation handle_info is called when some data with a fixed size is available. However the JSON messages can be large so that handle_info is called multiple times with only parts of the message. I then do:
String.ends_with?(new_msg, "\n")
to put together whole messages.
This feels very slow, what I would like is to move this logic down and only have handle_info called when a complete message is available on the socket, that is when a message terminated with \n has arrived.
Is there any support for this in Erlang/Elixir?
Marked As Solved
voltone
For stream-based sockets, including ssl, Erlang can do the buffering for you for a number of packet formats, including line protocols. The mode is controlled through the packet option: http://erlang.org/doc/man/inet.html#setopts-2.
So, to get messages from a TLS socket delivered at line break boundaries:
:ssl.connect('example.net', 443, packet: :line)







