a simple(?) gen_tcp question

Dietmar Admin Schaefer dietmar@REDACTED
Wed Jul 14 16:44:31 CEST 2004


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