capricorn 2.0.8 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/erlang/lib/capricorn/ebin/capricorn.app +2 -1
  2. data/erlang/lib/capricorn/include/capricorn.hrl +1 -0
  3. data/erlang/lib/capricorn/src/cap_cluster_gems.erl +6 -1
  4. data/erlang/lib/capricorn/src/cap_console_dispatcher.erl +214 -0
  5. data/erlang/lib/capricorn/src/cap_machine_apps.erl +25 -1
  6. data/erlang/lib/capricorn/src/cap_sup.erl +14 -0
  7. data/erlang/lib/ejson/Makefile +24 -0
  8. data/erlang/lib/ejson/ebin/ejson.app +9 -0
  9. data/erlang/lib/ejson/include/ejson.hrl +40 -0
  10. data/erlang/lib/ejson/rebar.config +3 -0
  11. data/erlang/lib/ejson/src/ejson.erl +22 -0
  12. data/erlang/lib/ejson/src/ejson_decode.erl +337 -0
  13. data/erlang/lib/ejson/src/ejson_encode.erl +124 -0
  14. data/erlang/lib/ejson/test/arrays.escript +47 -0
  15. data/erlang/lib/ejson/test/compound.escript +56 -0
  16. data/erlang/lib/ejson/test/literals.escript +30 -0
  17. data/erlang/lib/ejson/test/numbers.escript +70 -0
  18. data/erlang/lib/ejson/test/objects.escript +51 -0
  19. data/erlang/lib/ejson/test/strings.escript +49 -0
  20. data/erlang/lib/ejson/test/timing.escript +43 -0
  21. data/erlang/lib/ejson/test/timing.json +382 -0
  22. data/erlang/lib/ejson/vendor/mochijson2.erl +621 -0
  23. data/erlang/lib/ejson/vendor/rfc4627.erl +625 -0
  24. data/erlang/lib/misultin/LICENSE.txt +41 -0
  25. data/erlang/lib/misultin/Makefile +26 -0
  26. data/erlang/lib/misultin/README.txt +120 -0
  27. data/erlang/lib/misultin/ebin/misultin.app +9 -0
  28. data/erlang/lib/misultin/examples/misultin_compress.erl +43 -0
  29. data/erlang/lib/misultin/examples/misultin_echo.erl +58 -0
  30. data/erlang/lib/misultin/examples/misultin_file.erl +43 -0
  31. data/erlang/lib/misultin/examples/misultin_gen_server.erl +158 -0
  32. data/erlang/lib/misultin/examples/misultin_get_variable.erl +55 -0
  33. data/erlang/lib/misultin/examples/misultin_hello_world.erl +43 -0
  34. data/erlang/lib/misultin/examples/misultin_rest.erl +68 -0
  35. data/erlang/lib/misultin/examples/misultin_ssl.erl +51 -0
  36. data/erlang/lib/misultin/examples/misultin_stream.erl +55 -0
  37. data/erlang/lib/misultin/examples/misultin_websocket_event_example.erl +103 -0
  38. data/erlang/lib/misultin/examples/misultin_websocket_example.erl +95 -0
  39. data/erlang/lib/misultin/include/misultin.hrl +95 -0
  40. data/erlang/lib/misultin/make.bat +55 -0
  41. data/erlang/lib/misultin/priv/README.txt +12 -0
  42. data/erlang/lib/misultin/priv/test_certificate.pem +21 -0
  43. data/erlang/lib/misultin/priv/test_privkey.pem +18 -0
  44. data/erlang/lib/misultin/rebar.config +3 -0
  45. data/erlang/lib/misultin/src/misultin.app.src +9 -0
  46. data/erlang/lib/misultin/src/misultin.erl +338 -0
  47. data/erlang/lib/misultin/src/misultin_http.erl +488 -0
  48. data/erlang/lib/misultin/src/misultin_req.erl +280 -0
  49. data/erlang/lib/misultin/src/misultin_socket.erl +193 -0
  50. data/erlang/lib/misultin/src/misultin_utility.erl +357 -0
  51. data/erlang/lib/misultin/src/misultin_websocket.erl +252 -0
  52. data/erlang/lib/misultin/src/misultin_ws.erl +78 -0
  53. data/erlang/rebar.config +2 -0
  54. data/erlang/rel/overlay/etc/capricorn/app.config +4 -0
  55. data/erlang/rel/reltool.config +5 -0
  56. data/lib/capricorn/recipes/apache-debian.rb +1 -1
  57. data/lib/capricorn/recipes/centos-plesk.rb +1 -1
  58. data/lib/capricorn/recipes/debian-plesk95.rb +1 -2
  59. data/lib/capricorn/recipes/macports.rb +1 -1
  60. data/lib/capricorn/version.rb +1 -1
  61. metadata +51 -4
@@ -0,0 +1,55 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: Gets the GET variable 'value' and prints it out as XML if found.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2009, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_get_variable).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
36
+
37
+ % stop misultin
38
+ stop() ->
39
+ misultin:stop().
40
+
41
+ % callback on request received
42
+ handle_http(Req) ->
43
+ % get params
44
+ Args = Req:parse_qs(),
45
+ case misultin_utility:get_key_value("value", Args) of
46
+ undefined ->
47
+ Req:ok([{"Content-Type", "text/xml"}], "<misultin_test><error>no value specified</error></misultin_test>");
48
+ Value ->
49
+ Req:ok([{"Content-Type", "text/xml"}], "<misultin_test><value>~s</value></misultin_test>", [Value])
50
+ end.
51
+
52
+
53
+
54
+
55
+
@@ -0,0 +1,43 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: Hello World.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2009, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_hello_world).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
36
+
37
+ % stop misultin
38
+ stop() ->
39
+ misultin:stop().
40
+
41
+ % callback on request received
42
+ handle_http(Req) ->
43
+ Req:ok("Hello World.").
@@ -0,0 +1,68 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: RESTful support.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2009, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_rest).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
36
+
37
+ % stop misultin
38
+ stop() ->
39
+ misultin:stop().
40
+
41
+ % callback function called on incoming http request
42
+ handle_http(Req) ->
43
+ % dispatch to rest
44
+ handle(Req:get(method), Req:resource([lowercase, urldecode]), Req).
45
+
46
+ % ---------------------------- \/ handle rest --------------------------------------------------------------
47
+
48
+ % handle a GET on /
49
+ handle('GET', [], Req) ->
50
+ Req:ok([{"Content-Type", "text/plain"}], "Main home page.");
51
+
52
+ % handle a GET on /users
53
+ handle('GET', ["users"], Req) ->
54
+ Req:ok([{"Content-Type", "text/plain"}], "Main users root.");
55
+
56
+ % handle a GET on /users/{username}
57
+ handle('GET', ["users", UserName], Req) ->
58
+ Req:ok([{"Content-Type", "text/plain"}], "This is ~s's page.", [UserName]);
59
+
60
+ % handle a GET on /users/{username}/messages
61
+ handle('GET', ["users", UserName, "messages"], Req) ->
62
+ Req:ok([{"Content-Type", "text/plain"}], "This is ~s's messages page.", [UserName]);
63
+
64
+ % handle the 404 page not found
65
+ handle(_, _, Req) ->
66
+ Req:ok([{"Content-Type", "text/plain"}], "Page not found.").
67
+
68
+ % ---------------------------- /\ handle rest --------------------------------------------------------------
@@ -0,0 +1,51 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: Hello World SSL.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2009, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_ssl).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end},
36
+ {ssl, [
37
+ {certfile, "../priv/test_certificate.pem"},
38
+ {keyfile, "../priv/test_privkey.pem"},
39
+ {password, "misultin"}
40
+ ]}
41
+ ]).
42
+
43
+ % stop misultin
44
+ stop() ->
45
+ misultin:stop().
46
+
47
+ % callback on request received
48
+ handle_http(Req) ->
49
+ % output
50
+ Req:ok("Hello World SSL.").
51
+
@@ -0,0 +1,55 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: Stream data gradually.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2009, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_stream).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
36
+
37
+ % stop misultin
38
+ stop() ->
39
+ misultin:stop().
40
+
41
+ % callback on request received
42
+ handle_http(Req) ->
43
+ % send headers
44
+ Req:stream(head, [{"Content-Type", "text/plain"}]),
45
+ % send stream
46
+ Req:stream("1"),
47
+ timer:sleep(2000),
48
+ % send stream
49
+ Req:stream("2"),
50
+ timer:sleep(2000),
51
+ % send stream
52
+ Req:stream("3"),
53
+ % close socket
54
+ Req:stream(close).
55
+
@@ -0,0 +1,103 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: Shows misultin Websocket With an event support.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2010, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_websocket_event_example).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([
36
+ {port, Port}, {loop, fun(Req) -> handle_http(Req, Port) end},
37
+ {ws_loop, fun(Ws) -> handle_websocket(Ws) end}, {ws_autoexit, false}
38
+ ]).
39
+
40
+ % stop misultin
41
+ stop() ->
42
+ misultin:stop().
43
+
44
+ % callback on request received
45
+ handle_http(Req, Port) ->
46
+ % output
47
+ Req:ok([{"Content-Type", "text/html"}],
48
+ ["
49
+ <html>
50
+ <head>
51
+ <script type=\"text/javascript\">
52
+ function addStatus(text){
53
+ var date = new Date();
54
+ document.getElementById('status').innerHTML = document.getElementById('status').innerHTML + date + \": \" + text + \"<br>\";
55
+ }
56
+ function ready(){
57
+ if (\"WebSocket\" in window) {
58
+ // browser supports websockets
59
+ var ws = new WebSocket(\"ws://localhost:", integer_to_list(Port) ,"/service\");
60
+ ws.onopen = function() {
61
+ // websocket is connected
62
+ addStatus(\"websocket connected!\");
63
+ // send hello data to server.
64
+ ws.send(\"hello server!\");
65
+ addStatus(\"sent message to server: 'hello server'!\");
66
+ };
67
+ ws.onmessage = function (evt) {
68
+ var receivedMsg = evt.data;
69
+ addStatus(\"server sent the following: '\" + receivedMsg + \"'\");
70
+ };
71
+ ws.onclose = function() {
72
+ // websocket was closed
73
+ addStatus(\"websocket was closed\");
74
+ };
75
+ } else {
76
+ // browser does not support websockets
77
+ addStatus(\"sorry, your browser does not support websockets.\");
78
+ }
79
+ }
80
+ </script>
81
+ </head>
82
+ <body onload=\"ready();\">
83
+ <div id=\"status\"></div>
84
+ </body>
85
+ </html>"]).
86
+
87
+ % callback on received websockets data
88
+ handle_websocket(Ws) ->
89
+ receive
90
+ {browser, Data} ->
91
+ Ws:send(["received '", Data, "'"]),
92
+ handle_websocket(Ws);
93
+ closed ->
94
+ % IMPORTANT: since we specified the {ws_autoexit, false} option, we need to manually ensure that this process exists
95
+ % [otherwise it will become a zombie]
96
+ io:format("The WebSocket was CLOSED!~n"),
97
+ closed;
98
+ _Ignore ->
99
+ handle_websocket(Ws)
100
+ after 5000 ->
101
+ Ws:send("pushing!"),
102
+ handle_websocket(Ws)
103
+ end.
@@ -0,0 +1,95 @@
1
+ % ==========================================================================================================
2
+ % MISULTIN - Example: Shows misultin Websocket support.
3
+ %
4
+ % >-|-|-(°>
5
+ %
6
+ % Copyright (C) 2010, Roberto Ostinelli <roberto@ostinelli.net>
7
+ % All rights reserved.
8
+ %
9
+ % BSD License
10
+ %
11
+ % Redistribution and use in source and binary forms, with or without modification, are permitted provided
12
+ % that the following conditions are met:
13
+ %
14
+ % * Redistributions of source code must retain the above copyright notice, this list of conditions and the
15
+ % following disclaimer.
16
+ % * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17
+ % the following disclaimer in the documentation and/or other materials provided with the distribution.
18
+ % * Neither the name of the authors nor the names of its contributors may be used to endorse or promote
19
+ % products derived from this software without specific prior written permission.
20
+ %
21
+ % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
22
+ % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ % PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24
+ % ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25
+ % TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ % NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ % POSSIBILITY OF SUCH DAMAGE.
29
+ % ==========================================================================================================
30
+ -module(misultin_websocket_example).
31
+ -export([start/1, stop/0]).
32
+
33
+ % start misultin http server
34
+ start(Port) ->
35
+ misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req, Port) end}, {ws_loop, fun(Ws) -> handle_websocket(Ws) end}]).
36
+
37
+ % stop misultin
38
+ stop() ->
39
+ misultin:stop().
40
+
41
+ % callback on request received
42
+ handle_http(Req, Port) ->
43
+ % output
44
+ Req:ok([{"Content-Type", "text/html"}],
45
+ ["
46
+ <html>
47
+ <head>
48
+ <script type=\"text/javascript\">
49
+ function addStatus(text){
50
+ var date = new Date();
51
+ document.getElementById('status').innerHTML = document.getElementById('status').innerHTML + date + \": \" + text + \"<br>\";
52
+ }
53
+ function ready(){
54
+ if (\"WebSocket\" in window) {
55
+ // browser supports websockets
56
+ var ws = new WebSocket(\"ws://localhost:", integer_to_list(Port) ,"/service\");
57
+ ws.onopen = function() {
58
+ // websocket is connected
59
+ addStatus(\"websocket connected!\");
60
+ // send hello data to server.
61
+ ws.send(\"hello server!\");
62
+ addStatus(\"sent message to server: 'hello server'!\");
63
+ };
64
+ ws.onmessage = function (evt) {
65
+ var receivedMsg = evt.data;
66
+ addStatus(\"server sent the following: '\" + receivedMsg + \"'\");
67
+ };
68
+ ws.onclose = function() {
69
+ // websocket was closed
70
+ addStatus(\"websocket was closed\");
71
+ };
72
+ } else {
73
+ // browser does not support websockets
74
+ addStatus(\"sorry, your browser does not support websockets.\");
75
+ }
76
+ }
77
+ </script>
78
+ </head>
79
+ <body onload=\"ready();\">
80
+ <div id=\"status\"></div>
81
+ </body>
82
+ </html>"]).
83
+
84
+ % callback on received websockets data
85
+ handle_websocket(Ws) ->
86
+ receive
87
+ {browser, Data} ->
88
+ Ws:send(["received '", Data, "'"]),
89
+ handle_websocket(Ws);
90
+ _Ignore ->
91
+ handle_websocket(Ws)
92
+ after 5000 ->
93
+ Ws:send("pushing!"),
94
+ handle_websocket(Ws)
95
+ end.