0

カウボーイ Web ソケットの例を実行しようとしていますが、エラーが発生し続けます。

{error,
    {bad_return,
        {{erws_app,start,[normal,[]]},
         {'EXIT',
             {undef,
                 [{websocket_sup,start_link,[],[]},
                  {application_master,start_it_old,4,
                      [{file,"application_master.erl"},{line,269}]}]}}}}}

アプリケーションの起動に使用している erlang コマンド: erl -pa ebin/ -pa deps/*/ebin

次に、application:start(app) を使用して、必要な依存アプリケーションを開始します。

rebar を使用してアプリケーションをコンパイルします

私が使用しているコード:

erws_app.erl

-module(erws_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1, start_link/2]).

start(_Type, _Args) ->
        Dispatch = cowboy_router:compile([
                {'_', [
                        {"/", cowboy_static, {priv_file, websocket, "index.html"}},
                        {"/websocket", ws_handler, []},
                        {"/static/[...]", cowboy_static, {priv_dir, websocket, "static"}}
                ]}
        ]),
        {ok, _} = cowboy:start_http(http, 100, [{port, 8080}],
                [{env, [{dispatch, Dispatch}]}]),
        websocket_sup:start_link().     

start_link(_Type, _Args) ->
        Dispatch = cowboy_router:compile([
                {'_', [
                        {"/", cowboy_static, {priv_file, websocket, "index.html"}},
                        {"/websocket", ws_handler, []},
                        {"/static/[...]", cowboy_static, {priv_dir, websocket, "static"}}
                ]}
        ]),
        {ok, _} = cowboy:start_http(http, 100, [{port, 8080}],
                [{env, [{dispatch, Dispatch}]}]),
        websocket_sup:start_link().

stop(_State) ->
        ok.

erws_handler.erl

-module(erws_handler).
-export([init/3]).
-export([websocket_init/3]).
-export([websocket_handle/3]).
-export([websocket_info/3]).
-export([websocket_terminate/3]).

init({tcp, http}, _Req, _Opts) ->
    {upgrade, protocol, cowboy_websocket}.

websocket_init(_TransportName, Req, _Opts) ->
    erlang:start_timer(1000, self(), <<"Hello!">>),
    {ok, Req, undefined_state}.

websocket_handle({text, Msg}, Req, State) ->
    {reply, {text, << "That's what she said! ", Msg/binary >>}, Req, State};
websocket_handle(_Data, Req, State) ->
    {ok, Req, State}.

websocket_info({timeout, _Ref, Msg}, Req, State) ->
    erlang:start_timer(1000, self(), <<"How' you doin'?">>),
    {reply, {text, Msg}, Req, State};
websocket_info(_Info, Req, State) ->
    {ok, Req, State}.

websocket_terminate(_Reason, _Req, _State) ->
    ok.

erws_sup.erl

-module(erws_sup).
-behaviour(supervisor).

%% API.
-export([start_link/0]).

%% supervisor.
-export([init/1]).

%% API.

-spec start_link() -> {ok, pid()}.
start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).

%% supervisor.

init([]) ->
    Procs = [],
    {ok, {{one_for_one, 10, 10}, Procs}}.

erws.app.src

{application, erws, [
    {description, ""},
    {vsn, "1"},
    {registered, []},
    {applications, [kernel,stdlib,crypto,cowboy,compiler,lager,syntax_tools]},
    {mod, { erws_app, []}},
    {env, []}
]}.

rebar.config

{erl_opts, [{parse_transform, lager_transform}]}.
{lib_dirs,["deps"]}.
{sub_dirs, ["rel"]}.

{deps, [
    {'lager', ".*", {
        git, "https://github.com/basho/lager.git", "2.0.2"}
    },
    {'ranch', ".*", {
        git, "https://github.com/extend/ranch.git", "0.9.0"}
    },
    {'cowlib', ".*", {
        git, "https://github.com/extend/cowlib.git", "0.4.0"}
    },
    {'cowboy', ".*", {
        git, "https://github.com/extend/cowboy.git", "0.9.0"}
    }
]}.

このエラーを解決するための助けをいただければ幸いです。

よろしく

4

1 に答える 1

1

エラー メッセージは、関数がerws_app:start/2関数を呼び出そうとしたwebsocket_sup:start_link/0が、そのような関数が存在しないことを示しています。

スーパーバイザ モジュールに という名前を付けたので、すべてを に置き換えerws_supます。websocket_sup:start_link()erws_app.erlerws_sup:start_link()

于 2014-02-15T12:33:59.600 に答える