joearms / ezwebframe Goto Github PK
View Code? Open in Web Editor NEWwebsockets framework toghter with cowboy as described in book
License: Other
websockets framework toghter with cowboy as described in book
License: Other
Mac OSX 10.10.5:
../ezwebframe-master$ gmake
...
....
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
a simple_demo of websockets....
Load the page http://localhost:1456/ in your browser
Starting:{ok,"/Users/7stud/erlang_programs/ezwebframe/ezwebframe-master/demos"}
Eshell V8.2 (abort with ^G)
1> {"init terminating in do_boot",{{badmatch,{error,{not_started,ssl}}},[{ezwebframe,start_link,2,[{file,"src/ezwebframe.erl"},{line,22}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ()
Crash dump is being written to: erl_crash.dump...done
make[1]: *** [all] Error 1
gmake: *** [Makefile:4: all] Error 2
33 cowboy:start_http(ezwebframe,
34 NumberOfAcceptors,
35 [{port, Port}],
36 [{env, [{dispatch, Dispatch}]}]),
the cowboy not exists this function any more now....
[root@neptune ezwebframe]# make
==> ezwebframe (get-deps)
Pulling cowboy from {git,"git://github.com/extend/cowboy.git","master"}
Cloning into 'cowboy'...
==> cowboy (get-deps)
Pulling cowlib from {git,"https://github.com/ninenines/cowlib","2.0.1"}
Cloning into 'cowlib'...
Pulling ranch from {git,"https://github.com/ninenines/ranch","1.4.0"}
Cloning into 'ranch'...
==> cowlib (get-deps)
==> ranch (get-deps)
rebar compile
==> cowlib (compile)
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:31: syntax error before: '{'
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:40: syntax error before: '{'
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:52: syntax error before: '{'
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:59: syntax error before: '{'
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:21: function decode/1 undefined
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:22: function decode/2 undefined
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:23: function encode/1 undefined
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:55: function encode/3 undefined
/root/ezwebframe/deps/cowlib/src/cow_base64url.erl:54: Warning: missing specification for function encode/2
ERROR: compile failed while processing /root/ezwebframe/deps/cowlib: rebar_abort
make: *** [all] Error 1
All of the demos fail on my laptop, probably for the same reason. Here's the error that comes up in the console:
WebSocket connection to 'ws://localhost:1456/websocket/clock1' failed: Error during WebSocket handshake: Unexpected response code: 400
This is on Chrome version 40.0.2214.94 (64-bit).
No error comes up on the server side:
ezwebframe:handle "/clocks/clock1.html"
ezwebframe_demos::dispatch /clocks/clock1.html => /Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/clocks/clock1.html
mapped to:"/Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/clocks/clock1.html"
ezwebframe:handle "/common/jquery-1.7.1.min.js"
ezwebframe:handle "/ezwebframe/websock.js"
ezwebframe_demos::dispatch /common/jquery-1.7.1.min.js => /Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/common/jquery-1.7.1.min.js
ezwebframe_demos::dispatch /ezwebframe/websock.js => /Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/../priv/websock.js
ezwebframe:handle "/clocks/clock1.css"
mapped to:"/Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/common/jquery-1.7.1.min.js"
mapped to:"/Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/../priv/websock.js"
ezwebframe_demos::dispatch /clocks/clock1.css => /Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/clocks/clock1.css
mapped to:"/Users/issactrotts/erlang/joe_armstrong_book/websockets/ezwebframe/demos/clocks/clock1.css"
I just forked the repo and using rebar I tried to build and run it.
Turns out that there's currently a new dependency on cowboy called cowlib. This means your make file in the demos directory doesn't work with the new cowlib dependency.
One way to fix this is to update line 5 in demos/Makefile to be:
-pa ../deps/*/ebin\
I guess with this change you wont need the "-pa ../deps/cowboy/ebin\ " in line 4.
Thanks
P/S: I'm a great fan. Can't stop reading everything you do
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]
deps/cowboy/src/cowboy_req.erl:1206: illegal use of variable 'Atom' in map
deps/cowboy/src/cowboy_req.erl:1209: illegal use of variable 'Atom' in map
deps/cowboy/src/cowboy_req.erl:1212: illegal use of variable 'Atom' in map
deps/cowboy/src/cowboy_req.erl:1233: illegal use of variable 'Key' in map
deps/cowboy/src/cowboy_req.erl:1244: illegal use of variable 'Key' in map
Everything goes well under Erlang/OTP 18.
hello,joe. I just run make
then occurred the error above.my erl version is 18.
I understand the explanations in the book, but am having difficulty understanding the code in ezwebframe.erl. One problem is the seemingly inconsistency between some of the 'cowboy'-related function calls in ezwebframe and documentation found in the cowboy website. For example:
For websockets, Cowboy website says:
First, the init/3 callback is called. This callback is common to all handlers. To establish a
Websocket connection, this function must return an upgrade tuple.
init(_, Req, Opts) -> {upgrade, protocol, cowboy_websocket}.
or
init(_Type, Req, Opts) -> {upgrade, protocol, cowboy_websocket, Req, Opts}.
But in ezwebframe.erl, I see init/2 with a return tuple of {cowboy_websocket, Req, Pid}, which I can't find anywhere in the Cowboy documentation. Is this from an older version of Cowboy? This is just one example. There are others.
I've successfully used the Yaws web server for a couple of projects in the past. Yaws worked well and unlike Cowboy, it is very well documented. I'm taking a look at Cowboy only because Joe used it in his book, which in my opinion, gave it some credibility. Also, I read somewhere that Cowboy is supposed to be a bit lighter weight and has better performance (maybe because of the use single precess per connection and binaries). But I'm struggling with it; the documentation is terrible.
Curious as to why Joe chose Cowboy over Yaws for his book.
From playing around with this (very cool btw), I noticed that if I attempted to launch my app from a directory other than where index.html resides, "/" would fail to be resolved, whereas if I specified "/index.html" it would be resolved fine.
This appears to be caused due to ezwebframe:handle/2, the logic is different when resolving "/" than any other page. This may be intentional (it makes sense to launch from wherever index.html is located after all), but it is surprising to see -
mapped to:"/location/where/index/is/for/realsies/located"
serve_abs:"index.html"
*** no page called "index.html"
when hitting "/", and have it load just fine when hitting "/index.html".
For a sake of code reuse you could make use of https://github.com/spawngrid/mimetypes
Cheers,
Gleb Peregud
Continuing from my previous bug posting a few minutes ago. I also think you need to add application:start(cowlib) in src/ezwebframe.erl.
It's a dependency to cowboy and needs to be running. Suggested update is the line in bold:
...
ok = application:start(crypto),
ok = application:start(ranch),
ok = application:start(cowlib),
ok = application:start(cowboy),
ok = web_server_start(Port, Dispatch).
...
Thanks
John Chukwuma
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.