[erlang-questions] Noob Question ...
Bernard Duggan
bernie@REDACTED
Fri Mar 6 23:32:34 CET 2009
Valentin Micic wrote:
>> The immediate thing that strikes me is that "127.0.0.1" should be
> {127,0,0,1}. In gen_tcp (erlang in general) the address is a tuple not a
> string.
>
> This is not correct -- gen_tcp supports string as well as tuple for dotted
> ip address specification
That's true, and for most cases it will work fine, however if you pass
gen_udp a string address it will always call (from memory) gethostbyname
- I presume the same probably applies to gen_tcp. This turns out to be
a relatively slow operation - if you're only doing one (or even a
hundred) lookups, it's not an issue - we started to strike performance
problems, however, doing large amounts of gen_udp:send operations with
an IP passed as a string. These went away when we changed it to a tuple.
It's not going to be a problem here, but using the tuple form is
probably a good habit to get into so that it doesn't bite you in the future.
Cheers,
B
More information about the erlang-questions
mailing list