简体   繁体   中英

I am stuck at this error message in erlang for concurrency

Here are my imports and exports

-import(calling, [create_receiver_process/1, create_senders_process/1]).
-export([main/1, read_file/1, merge_method/1, merge_method/2, master_process/1, print_data/1]).

Here is the code I suspect, is causing the error

{gotintro, Sender, Receiver, Time} ->
            io:format("~p received intro message from ~p [~p]~n", [Receiver, Sender, Time]),
            master_process(RPs);        

        {gotreply, Sender, Receiver, Time} ->
            io:format("~p received reply message from ~p [~p]~n", [ Sender,Receiver, Time]),
            master_process(RPs)

and here is the error, I am getting

=ERROR REPORT==== 14-Jun-2020::20:58:23.841027 ===
Error in process <0.88.0> with exit value:
{undef,[{test,base_receiver_method,[],[]}]}

=ERROR REPORT==== 14-Jun-2020::20:58:23.848795 ===
Error in process <0.100.0> with exit value:
{undef,[{test,send_message,[john,joe],[]}]}

Here is base_receiver_method

base_receiver_method() ->
    receive
        {intro , Sender, Receiver, Time} ->
            io:format("Message Intro ~p ~p~n", [Sender, Receiver]),
            Name = string:concat(lists:flatten(io_lib:format("~p", [Sender])), "sender"),
            N = list_to_atom(Name),
            N ! {reply, Receiver, Sender, Time},
            timer:sleep(round(rand:uniform() * 100)),
            master ! {gotintro, Receiver, Sender, Time},
            base_receiver_method();
        {reply , Sender, Receiver, Time} ->
            io:format("Message Reply ~p ~p~n", [Sender, Receiver]),
            timer:sleep(round(rand:uniform() * 100)),
            master ! {gotreply, Receiver,Sender, Time},
            base_receiver_method()
    after 1000 ->
        exit("Time Up")
    end.

Here is send_message:

send_message(S, R) ->
    Name = string:concat(lists:flatten(io_lib:format("~p", [R])), "receiver"),
    N = list_to_atom(Name),
    {_, _, Time} = erlang:now(),
    N ! {intro, S, R, Time}.

Try to export or import functions what you try to call. The error message mean that the functions what you try to call is undefined, looks like you need update import and put base_receiver_method/0, send_message/2 , but before it, try export those functions in the module from which you try do import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM