problems spawing processes

Dietmar Schaefer dietmar@REDACTED
Tue Jan 25 16:02:42 CET 2005


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