unable to reconnect to server
Dietmar Schaefer
dietmar@REDACTED
Mon Jan 31 12:21:43 CET 2005
Hi !
I am trying to establish a connection to a client via gen_tcp:
-module(test3).
-define (PORT,1234).
-export([start/0]).
start() ->
start(?PORT).
start(Port) ->
Pid = spawn_link(fun() -> server(Port) end).
server(Port) ->
Opts = [{reuseaddr, true},{packet, 0}, {active, false}],
{ok,Socket} = gen_tcp:listen(Port,Opts),
loop(Socket).
loop(Socket) ->
{ok,Sock} = gen_tcp:accept(Socket),
register(test,spawn_link(fun() -> do_send(Sock) end)),
process_flag(trap_exit, true), %% get informed
when server failed
loop(Socket).
reqHandler(Sock) ->
do_send(Sock),
gen_tcp:close(Sock).
do_send(Socket) ->
receive
{msg,Msg} -> io:format("message received ~n"),
case fill(integer_to_list(string:len(Msg)),3) of
{ok,String} ->
gen_tcp:send(Socket,String),
cmmc_util:msleep(100),
gen_tcp:send(Socket,Msg),
do_send(Socket);
{error,_} -> ok
end;
{action,Action} -> ok;
{'EXIT',From,What} -> io:format("Bingo ~n"), gen_tcp:close(Socket)
end.
When I terminate the client and try to start it again I get
Error in process <0.322.0> on node 'cmmc@REDACTED' with exit value:
{badarg,[{erlang,register,[test,<0.325.0>]},{test3,loop,1}]}
What has erlang:register to do with that ?
What's wrong anyway ?
Any hint ?
Regards
Dietmar
More information about the erlang-questions
mailing list