a simple(?) gen_tcp question

Joe Armstrong <>
Wed Jul 14 15:09:39 CEST 2004


Hi Dieter,

There is nothing wrong with your program - it works fine I compiled and ran
it without error on my machine.

If your program is ok then your environment must be screwed up.

If you have the latest OTP then you can check that you are getting
the correct version of gen_tcp

You can start by checking which version of gen_tcp you are picking up.

On my system I get something like this:

> code:which(gen_tcp).
 "/usr/local/lib/erlang/lib/kernel-2.9.6.6/ebin/gen_tcp.beam"
> cd /usr/local/lib/erlang/lib/kernel-2.9.6.6/src/
> gen_tcp.erl
    191     512    4018 gen_tcp.erl
> md5sum gen_tcp.erl
ad3e400c72456db0403b02718702791b  gen_tcp.erl

  If  you  don't get  something  like  this it  might  be  an idea  to
re-install the system.

  You can also try evaluating 

    code:clash()

  And looking at the results - this will tell you if there are two different
versions of gen_tcp lurking in your path.

  Hope this helps

  Cheers

/Joe in rainy Stockholm - the worse summer for 76 years (:-



On Wed, 14 Jul 2004, Dietmar Admin Schaefer wrote:

> Hi !
> 
> 
> Can somebody please tell me why I get
> 
> 
> exited: {undef,[{gen_tcp,listen,[5678,[binary,{packet,0},{active,false}]]},
>                    {mygen_tcp,server,0}]} **
> 
> 
> when I try to start my (test)program ?
> 
> -module(mygen_tcp).
> -define(PORT,5678).
> -export([start/0, client/0, server/0]).
> 
> start() ->
>     io:format("o.k. I will listen on port ~p~n", [?PORT]),
>     io:format("o.k. I will send on port ~p~n", [?PORT]),
>     spawn_link(?MODULE, server, []),
>      spawn_link(?MODULE, client, []).
> 
>   client() ->
>            MyHost = "localhost",
>            {ok, Sock} = gen_tcp:connect(MyHost, 5678, [binary, {packet, 
> 0}]),
>            ok = gen_tcp:send(Sock, "Some Data"),
>            ok = gen_tcp:close(Sock).
>            
> 
>  server() ->             
>            case  gen_tcp:listen(5678, [binary, {packet, 0},{active, 
> false}])
>            of
>              {ok, LSock} ->
>              {ok, Sock} = gen_tcp:accept(LSock),
>              {ok, Bin} = do_recv(Sock, []),
>              ok = gen_tcp:close(Sock),
>              Bin
>               end.
> 
>  do_recv(Sock, Bs) ->
>            case gen_tcp:recv(Sock, 0) of
>                {ok, B} ->
>                    do_recv(Sock, [Bs, B]);
>                {error, closed} ->
>                    {ok, list_to_binary(Bs)}
>            end.
> 
> did I miss some basics ???
> 
> 
> 
> regards
> 
> Dietmar
> 




More information about the erlang-questions mailing list