Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 56 lines (51 sloc) 2.362 kB
dc565e4 @ostinelli added stream example
authored
1 % ==========================================================================================================
2 % MISULTIN - Example: Stream data gradually.
3 %
4 % >-|-|-(°>
5 %
b6f5286 @ostinelli - added max_connections options parameter, which specifies maximum co…
authored
6 % Copyright (C) 2011, Roberto Ostinelli <roberto@ostinelli.net>
dc565e4 @ostinelli added stream example
authored
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).
b5e0272 @ostinelli primary websockets support added.
authored
31 -export([start/1, stop/0]).
dc565e4 @ostinelli added stream example
authored
32
a483d2e @ostinelli modified examples to have a configurable port.
authored
33 % start misultin http server
34 start(Port) ->
35 misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
dc565e4 @ostinelli added stream example
authored
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
Something went wrong with that request. Please try again.