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: inet — OTP 29.0.2 (kernel 11.0.2).
So, to get messages from a TLS socket delivered at line break boundaries:
:ssl.connect('example.net', 443, packet: :line)
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








