elixir-socket example code

454 views
Skip to first unread message

Robin Hilliard

unread,
Feb 21, 2015, 2:57:09 AM2/21/15
to elixir-l...@googlegroups.com
Hi all,

First post here, I'm co-convenor of the Sydney Erlang UG, happily and noob-ily scaling the Elixir learning curve. In https://github.com/meh/elixir-socket/blob/v0.2.5/lib/socket.ex there is a code example:

{ :ok, client } = Sockect.connect "tcp://google.com:80"
client.send "GET / HTTP/1.1\r\n"
client.recv

I get an argument error error running this. I'm very suspicious of the dot notation because it looks very object-y but I thought maybe there is some macro magic that makes it work (the macro book is still being shipped and is probably bobbing around in a container south of Hawaii). All the other examples use the pipe. Confirmation of this being incorrect or pointer to how it should work much appreciated.

Cheers,
Robin


Richard B

unread,
Feb 25, 2015, 9:21:11 AM2/25/15
to elixir-l...@googlegroups.com
I noticed the first line of your code references the "Sockect" module rather than "Socket." Could the typo be the cause of the error you're having? If that isn't the cause, paste the full error message in here so we can look further.

Richard

Vincent Siliakus

unread,
Feb 25, 2015, 6:30:25 PM2/25/15
to elixir-l...@googlegroups.com
Hi Robin,

Welcome to this list! I haven't used this library myself, but I quickly scanned the code base and I think it's an outdated example. Before maps and structs, Elixir had a record implementation that allowed this kind of syntax by using Erlang's somewhat controversial tuple module functionality.

-Vincent

Eric Meadows-Jönsson

unread,
Feb 26, 2015, 3:05:07 AM2/26/15
to elixir-l...@googlegroups.com
It's not necessarily old syntax. The `Socket.connect` receives a URL containing the intended protocol (TCP here). `client` could be a module that implements the socket interface for TCP connections. You can bind a module to a variable and still call it.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/1f72294a-7e60-4465-8d94-e809816e297a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson
Reply all
Reply to author
Forward
0 new messages