我试图写一个函数来终止我的程序。它叫做quitChat。但是当我调用函数messenger:quitChat()
时,我得到了这个错误。
** exception error: bad argument
in function exit/2
called as exit(undefined,kill)
in call from messenger:quitChat/0 (messenger.erl, line 26)
到目前为止,我使用的是以下代码:
-module(messenger).
-export([start_server/0, server/1, logon/1, logoff/0, message/2, client/2,
requestChat/1, quitChat/0]).
server_node() ->
messenger@timberlake.
server(User_List) ->
receive
{From, logon, Name} ->
New_User_List = server_logon(From, Name, User_List),
server(New_User_List);
{From, logoff} ->
New_User_List = server_logoff(From, User_List),
server(New_User_List);
{From, message_to, To, Message} ->
server_transfer(From, To, Message, User_List),
io:format("list is now: ~p~n", [User_List]),
server(User_List)
end.
start_server() ->
register(messenger, spawn(messenger, server, [[]])).
quitChat() ->
exit(whereis(messenger), kill).
2条答案
按热度按时间iovurdzv1#
使用
erlang:halt/0,1
。文件
vjhs03f72#
按以下方式更改您的quitChat: