2012-01-18 7 views
2

에서 간단한 응용 프로그램을 실행할 수 없습니다,하지만 다음과 같은 오류와 함께 작동하도록 거부 :내가 얼랑에서 간단한 응용 프로그램을 작성 얼랑

=SUPERVISOR REPORT==== 18-Jan-2012::15:03:27 === 
Supervisor: {<0.60.0>,my_sup} 
Context: start_error 
Reason:  {'EXIT',{undef,[{my,start,[{8077,none}]}, 
          {supervisor,do_start_child,2}, 
          {supervisor,start_children,3}, 
          {supervisor,init_children,2}, 
          {gen_server,init_it,6}, 
          {proc_lib,init_p_do_apply,3}]}} 
Offender: [{pid,undefined}, 
       {name,my}, 
       {mfa,{my,start,[{8077,none}]}}, 
       {restart_type,permanent}, 
       {shutdown,brutal_kill}, 
       {child_type,worker}] 

=INFO REPORT==== 18-Jan-2012::15:03:27 === 
application: my 
exited: {shutdown,{my_app,start,[normal,[noarg]]}} 
type: temporary {error,{shutdown,{my_app,start,[normal,[noarg]]}}} 

그리고 모듈 :

my.erl

-module(my). 
-export([start/2, stop/0]). 

start(Port,_arg) -> 
io:format("starting my"). 

stop() -> 
    ok. 

my_app.erl 응용 프로그램 모듈, 수행 application 동작.

-module(my_app). 
-behaviour(application). 
-export([start/2, stop/1]). 

    start(_Type, _Args) -> 
    io:format("my server starting~n"), 
    my_sup:start_link(). 

    stop(_State) -> 
    io:format("my server terminating~n"), 
    ok. 

my_sup.erl 감독자 논리

-module(my_sup). 
-behaviour(supervisor). 
-export([start_link/0]). 
-export([init/1]). 

start_link() -> 
    supervisor:start_link(my_sup, []). 

init(_Args) -> 
{ok, { 
     {one_for_one, 10, 60}, 
      [{my, {my, start, [{8077,none}] 
     }, 
     permanent, brutal_kill, worker, [my]}]}}. 

구성 파일 (my.app가) : 당신이 추천처럼

{application, my, 
[ 
    {description, "Demo"}, 
    {vsn, "1.0"}, 
    {id, "hello"}, 
    {modules,  [my,my_sup]}, 
    {registered, [my,my_sup]}, 
    {applications, [kernel, stdlib]}, 
    %% 
    %% mod: Specify the module name to start the application, plus args 
    %% 
    {mod, {my_app, [noarg]}}, 
    {env, []} 
    ] 
}. 

나는 아이의 사양을 변경,하지만 문제는 여전히 남아있다.

=SUPERVISOR REPORT==== 19-Jan-2012::00:34:21 === 
Supervisor: {<0.96.0>,my_sup} 
Context: start_error 
Reason:  <0.97.0> 
Offender: [{pid,undefined}, 
      {name,my}, 
      {mfa,{my,start,[8077,none]}}, 
      {restart_type,permanent}, 
      {shutdown,brutal_kill}, 
      {child_type,worker}] 


=ERROR REPORT==== 19-Jan-2012::00:34:21 === 
Error in process <0.97.0> with exit value: 
{{badmatch,{error,eaddrinuse}},[{my,'-  start/2-fun-0-',1}]} 


=INFO REPORT==== 19-Jan-2012::00:34:21 === 
application: my 
exited: {shutdown,{my_app,start,[normal,[noarg]]}} 
type: temporary 
{error,{shutdown,{my_app,start,[normal,[noarg]]}}} 

답변

3

my:start/2는 두 개의 인수를해야하지만, 아이 사양에 당신은 단지 그것을 하나 개의 인수 ({8077,none}를) 제공합니다. 당신이 아이의 사양을 변경할 수 있습니다 : 감독자 사양의 제쳐두고 들여 쓰기 라인 파괴로

{my, {my, start, [8077,none]}, permanent, brutal_kill, worker, [my]} 

것은 조금 떨어져이 어려운 무엇에 속한 것을보고하고있다.

편집 : 새로운 오류

이 이전과 같은 문제가되지 않습니다에 코멘트. eaddrinuse이라는 새로운 오류가 발생합니다. 이는 일반적으로 이미 사용중인 IP 주소/포트를 사용하려고 함을 의미합니다. 이것은 코드에서 소켓 프로그래밍을하고 있음을 암시합니다.

1

귀하의 감독자는 my : start가 인수를 하나 취해야한다고 지정하지만 두 개가 필요합니다. 당신은 아마에 아이 스펙을 변경하려면 :

{one_for_one, 10, 60},[{my, {my, start, [8077,none]} 
0

my:start/2은 잘못된 반환 값을 제공합니다. 수퍼바이저는 튜플 {ok,Pid}을 기대하며 함수는 ok을 반환합니다 (마지막 호출은 ok을 반환하므로 사용자의 기능도 마찬가지입니다). 관리자를 사용하려면 새 프로세스를 생성하여 감독자에게 연결해야합니다. 예를 들어, start(_) -> {ok,spawn_link(fun() -> io:format("~w started~n",[self()]),timer:sleep(5000),io:format("~w exiting~n",[self()]) end)}. 이 작업을 수행해야합니다.

관련 문제