problems spawing processes
Fredrik Linder
fredrik.linder@REDACTED
Tue Jan 25 16:27:29 CET 2005
Hi
The processes probably gets spawned alright, but there is an error in the first io:format/2 in getMessages/1.
The second argument must be a list, change it to:
io:format("get messages from port ~p~n",[Port]),
and you will most likely get the printout.
Note: the trap_exists only work if the process you spawn is linked (by either using spawn_link or link it explicitly).
/Fredrik
> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED]On Behalf Of
> Dietmar Schaefer
> Sent: den 25 januari 2005 16:03
> To: erlang-questions@REDACTED
> Subject: problems spawing processes
>
>
> Hi !
>
>
> I am trying to spawn 2 processes:
>
>
>
> -export([startComm/2, getMessages/1, sendMessages/1]).
>
>
> startComm(ListenPort,SendPort) ->
> io:format("sendport = ~p~n", [SendPort]),
> io:format("listenport = ~p~n",[ListenPort]),
>
> register (getProc,spawn(?MODULE, getMessages, [ListenPort])),
> register (sendProc,spawn(?MODULE, sendMessages, [SendPort])),
> %% process_flag(trap_exit, true), %%
> get informed
> when server failed
>
> io:format("Hello world~n").
>
>
>
> where
>
> %% @doc
> %% gets messages from 4DP (mainly AuS)
> %% messages are received as lists of strings
> %%
> getMessages(Port) when integer(Port) ->
> io:format("get messages from port ~p~n",Port),
> case gen_tcp:listen(Port, [ {reuseaddr, true},
> {packet, 0},
> {active, false}]) of
> {ok, ListenSocket} ->
> io:format(" I listen to socket ~p~n", [Port]),
>
> {ok,Sock} = gen_tcp:accept(ListenSocket),
> {ok, Bin} = do_recv(Sock),
> ok = gen_tcp:close(Sock);
>
> {error,Reason} -> io:format("an error occured
> listening on
> socket reason : ~p~n",[Reason]);
> Other -> io:format("Can't listen to
> socket ~p~n",
> [Other])
> end.
>
>
> %% @doc
> %% this is the receiving routine
> %%
> do_recv(Sock) ->
> case gen_tcp:recv(Sock,0) of
> {ok,Bin} -> io:format("o.k. I got: ~p~n",
> [decode(Bin)]),
> do_recv(Sock);
>
> {error,Reason} -> {error,closed};
> {EXIT,_} -> {error,exit}
> end.
>
>
> and another one in the same manner but none will be started.
>
>
>
> I only get:
>
> sendport = 1235
> listenport = 1234
> Hello world
> ok
>
>
>
> can anyone point me to the right direction ?
>
>
>
> regards
>
>
> Dietmar
>
>
> P.S.
>
> The problem arised after an intoduction of a new module where all
> communication
> takes place
>
>
>
>
More information about the erlang-questions
mailing list