[erlang-questions] Noob Question ...

Valentin Micic v@REDACTED
Fri Mar 6 14:56:46 CET 2009


There are three ways to receive data using gen_tcp, depending on which mode
you've selected. The gen_tcp:recv may be used only if your socket has been
opened with additional option flag {active, false} - which means that you do
not want to receive unsolicited traffic. , thus, just change your line from:

 

    case gen_tcp:connect("127.0.0.1", Port, [list,{packet,0}]) of



to 

 

case gen_tcp:connect("127.0.0.1", Port, [list,{packet,0}, {active, false}])
of



and the code should work.

The error message is a bit misleading, but if you call gen_tcp:recv on a
socket that does not contain {active, fase}, gen_tcp:recv shall return
{error,einval}, which will in turn cause function_clause error message.

 

V.

  _____  

From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Shelby Ramsey
Sent: 06 March 2009 04:22 AM
To: erlang-questions@REDACTED
Subject: [erlang-questions] Noob Question ...

 

Hello! 

I'm trying to become an erlang convert (from Python) and I do mostly network
programming.

So I wrote up this little tidbit:

-module(test).
-export([client/1]).

client([Port]) ->
    case gen_tcp:connect("127.0.0.1", Port, [list,{packet,0}]) of
        {ok, Socket} ->
            gen_tcp:send(Socket,"auth iltd!dy69?\r\n\r\n"),
            gen_tcp:send(Socket,"event plain text\r\n\r\n"),
            loop(Socket);
        {error, Reason} ->
            print_stuff([Reason]),
            ok
    end.

loop(Socket) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Data} ->
            print_stuff([Data]),
            loop(Socket);
        {error, closed} ->
            ok
    end.

print_stuff([Text]) ->
    io:format("~w", [Text]).

It compiles ... but when I run ... well ... it spits this:

=ERROR REPORT==== 5-Mar-2009::20:19:27 ===
Error in process <0.30.0> with exit value:
{function_clause,[{test,client,[8021]},{erl_eval,do_apply,5},{shell,exprs,6}
,{shell,eval_loop,3}]}

** exited: {function_clause,[{test,client,[8021]},
                             {erl_eval,do_apply,5},
                             {shell,exprs,6},
                             {shell,eval_loop,3}]} **


So what did I hose up?  And more importantly ... where is some documentation
re: how to debug the "error report".

Thanks for any assistance!

SDR

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090306/a095eb63/attachment.htm>


More information about the erlang-questions mailing list