jononomo
Do I have to provide an actual numerical IP address to :gen_tcp.connect?
I have the following line in an elixir module:
{:ok, socket} = :gen_tcp.connect("my-appname-1842614232.us-east-1.elb.amazonaws.com", 4000, opts)
The error I am getting is: “evaluator process exited with reason: :badarg”
It worked fine when I had the line like this:
{:ok, socket} = :gen_tcp.connect({10, 247, 4, 104}, 4000, opts)
So my question is – do I have to use an actual IP address?
Marked As Solved
NobbZ
According to the documentation it has to be inet:hostname() which is string(), which in elixir means char_list, so your hostname has to be 'example.com'. Alternatively you can also use the c-sigil (~c[example.com])
Also Liked
entone
notice the single quotes ' instead of double "
Generally when interacting directly with Erlang libs, they expect char lists
NobbZ
Yes, they are.
The spec of :gen_tcp.connect/3:
connect(Address, Port, Options) → {ok, Socket} | {error, Reason}
Types
- Address = inet:socket_address() | inet:hostname()
- [other types omitted since they are unimportant here]
inet:hostname() (which is :inet.hostname in elixir syntax) is defined as follows:
hostname() = atom() | string()
Erlangs string() type is equal to elixirs charlist type.
charlists can be created using the charlist literal, which is an single-quoted “string”. Also one can use the c and C sigils to create them, when one wants to be a little bit more explicit.
And as @PatNowak correctly tells, you can convert anything implementing List.Chars by passing it to Kernel.to_charlist/1
Nicd
You should mark this thread as solved so others can see the answer right away and see it as solved in the thread list. ![]()
Last Post!
jononomo
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









