启动websocket应用程序时出错

启动websocket应用程序时出错,websocket,erlang,cowboy,Websocket,Erlang,Cowboy,我正在尝试运行cowboy web套接字示例,但一直遇到错误: {error, {bad_return, {{erws_app,start,[normal,[]]}, {'EXIT', {undef, [{websocket_sup,start_link,[],[]}, {application_master,start_it_old,4,

我正在尝试运行cowboy 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)启动所需的依赖项应用程序

我使用钢筋来编译应用程序

我正在使用的代码:

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.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"}
    }
]}.
非常感谢帮助解决此错误


关于

错误消息显示函数
erws\u app:start/2
尝试调用函数
websocket\u sup:start\u link/0
,但不存在此类函数

您已将监控模块命名为
erws\u sup
,因此将
erws\u app.erl
中的所有
websocket\u sup:start\u link()
替换为
erws\u sup:start\u link()

{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"}
    }
]}.