<div dir="ltr">All,<br>I am trying to establish an websocket connection using cowboy. I am using the base example given in cowboy websocket github. I am getting following crash:<br><br>2015-01-15 20:40:01.777 [error] emulator Error in process <0.185.0> on node 'erws@sasnedatzad07' with exit value: {[{re<br>ason,undef},{mfa,{erws_handler,terminate,3}},{stacktrace,[{lager,debug,["terminate"],[]},{erws_handler,terminate,3,[{fi<br>le,"erws_handler.erl"},{line,48}]},{cowboy_handler,terminate,4,[{file,"cowboy_handler.erl"},{line,69}]},...<br><br><br>2015-01-15 20:40:01.781 [error] <0.81.0> Ranch listener http had connection process started with cowboy_protocol:start_<br>link/4 at <0.185.0> exit with reason: {[{reason,undef},{mfa,{erws_handler,terminate,3}},{stacktrace,[{lager,debug,["ter<br>minate"],[]},{erws_handler,terminate,3,[{file,"erws_handler.erl"},{line,48}]},{cowboy_handler,terminate,4,[{file,"cowbo<br>y_handler.erl"},{line,69}]},{cowboy_handler,execute,2,[{file,"cowboy_handler.erl"},{line,54}]},{cowboy_protocol,execute<br>,4,[{file,"cowboy_protocol.erl"},{line,467}]}]},{req,[{socket,#Port<0.2498>},{transport,ranch_tcp},{connection,keepaliv<br>e},{pid,<0.185.0>},{method,<<"GET">>},{version,'HTTP/1.1'},{peer,{{10,69,209,221},49793}},{host,<<"sas755dev.hss.vzwcor<br><a href="http://p.com">p.com</a>">>},{host_info,undefined},{port,10100},{path,<<"/websocket">>},{path_info,undefined},{qs,<<>>},{bindings,[]},{hea<br>ders,[{<<"host">>,<<"<a href="http://sas755dev.hss.xxxxxx.com:10100">sas755dev.hss.xxxxxx.com:10100</a>">>},{<<"user-agent">>,<<"Mozilla/5.0 (Windows NT 6.1; rv:34.0) Gec<br>ko/20100101 Firefox/34.0">>},{<<"accept">>,<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>},{<<"a<br>ccept-language">>,<<"en-US,en;q=0.5">>},{<<"accept-encoding">>,<<"gzip, deflate">>},{<<"sec-websocket-version">>,<<"13"<br>>>},{<<"origin">>,<<"null">>},{<<"sec-websocket-key">>,<<"Uj2HLRfte83Kyu9r9qEesQ==">>},{<<"connection">>,<<"keep-alive,<br> Upgrade">>},{<<"pragma">>,<<"no-cache">>},{<<"cache-control">>,<<"no-cache">>},{<<"upgrade">>,<<"websocket">>}]},{meta<br>,[]},{body_state,waiting},{buffer,<<>>},{multipart,undefined},{resp_compress,false},{resp_state,waiting},{resp_headers,<br>[]},{resp_body,<<>>},{onresponse,undefined}]},{state,[]},{terminate_reason,{crash,error,undef}}],[{cowboy_handler,execu<br>te,2,[{file,"cowboy_handler.erl"},{line,59}]},{cowboy_protocol,execute,4,[{file,"cowboy_protocol.erl"},{line,467}]}]}<br><br>Here is my erws_handler.erl  file which is almost like example file provided in cowboy websocket github<br><br>-module(erws_handler).<br>-behaviour(cowboy_http_handler).<br>-behaviour(cowboy_websocket_handler).<br>-export([init/3, handle/2, terminate/3]).<br>-export([<br>    websocket_init/3, websocket_handle/3,<br>    websocket_info/3, websocket_terminate/3<br>]).<br><br>init({tcp, http}, _Req, _Opts) -><br>  {upgrade, protocol, cowboy_websocket}.<br><br><br>handle(Req, State) -><br>    lager:debug("Request not expected: ~p", [Req]),<br>    {ok, Req2} = cowboy_http_req:reply(404, [{'Content-Type', <<"text/html">>}]),<br>    {ok, Req2, State}.<br><br><br>websocket_init(_TransportName, Req, _Opts) -><br>    lager:debug("init websocket"),<br>    {ok, Req, undefined_state}.<br><br>websocket_handle({text, Msg}, Req, State) -><br>    lager:debug("Got Data: ~p", [Msg]),<br>    {reply, {text, << "responding to ", Msg/binary >>}, Req, State, hibernate };<br><br><br>websocket_handle(_Any, Req, State) -><br>    lager:debug("Got Any"),<br>    {reply, {text, << "whut?">>}, Req, State, hibernate }.<br><br>websocket_info({timeout, _Ref, Msg}, Req, State) -><br>    lager:debug("websocket info_timeout"),<br>    {reply, {text, Msg}, Req, State};<br><br>websocket_info(_Info, Req, State) -><br>    lager:debug("websocket info"),<br>    {ok, Req, State, hibernate}.<br><br>websocket_terminate(_Reason, _Req, _State) -><br>    % lager:debug("websocket terminate. reason: ~p",[_Reason]),<br>    lager:debug("websocket terminate"),<br>    ok.<br><br>terminate(_Reason, _Req, _State) -><br>     % lager:debug("terminate. Reason : ~p",[_Reason]),<br>     lager:debug("terminate"),<br>    ok.<br><br>I am trying from a simple html file through Mozilla Firefox :<br><br>ws = new WebSocket("ws://<a href="http://sas755dev.hss.xxxxxx.com:10100/websocket">sas755dev.hss.xxxxxx.com:10100/websocket</a>");<br><br>I need to provide port number with host name. Is that ok? Does cowboy support it? Is providing port number causing this issue? If not, then what else? Can anyone help me? Any help regarding this will be highly appreciated.<br>Thanks.<br>-<br>Akash<br></div>