Hello world/Web server: Difference between revisions

Content added Content deleted
(Changed to use builtin HTTP server)
m (Corrected typo, better names.)
Line 333: Line 333:
-module( hello_world_web_server ).
-module( hello_world_web_server ).


-export( [do/1, inets_start/2, inets_stop/1, task/0] ).
-export( [do/1, httpd_start/2, httpd_stop/1, task/0] ).


do( _Data ) ->
do( _Data ) ->
{proceed, [{response,{200,"Goodbye, World!"}}]}.
{proceed, [{response,{200,"Goodbye, World!"}}]}.


inets_start( Port, Module ) ->
httpd_start( Port, Module ) ->
Arguments = [{bind_address, "localhost"}, {port, Port}, {ipfamily, inet},
Arguments = [{bind_address, "localhost"}, {port, Port}, {ipfamily, inet},
{modules, [Module]},
{modules, [Module]},
Line 345: Line 345:
Pid.
Pid.
inets_stop( Pid ) ->
httpd_stop( Pid ) ->
inets:stop( stand_alone, Pid ).
inets:stop( stand_alone, Pid ).


task() ->
task() ->
Pid = inets_start( 8080, ?MODULE ),
Pid = httpd_start( 8080, ?MODULE ),
timer:sleep( 10000 ),
timer:sleep( 30000 ),
inets_stop( Pid ).
httpd_stop( Pid ).
</lang>
</lang>