RosettaCodeData/Task/Hello-world-Web-server/Erlang/hello-world-web-server.erl

22 lines
597 B
Erlang
Raw Permalink Normal View History

2013-06-05 21:47:54 +00:00
-module( hello_world_web_server ).
2013-04-10 21:29:02 -07:00
2013-06-05 21:47:54 +00:00
-export( [do/1, httpd_start/2, httpd_stop/1, task/0] ).
2013-04-10 21:29:02 -07:00
2013-06-05 21:47:54 +00:00
do( _Data ) ->
2014-01-17 05:32:22 +00:00
{proceed, [{response,{200,"Goodbye, World!"}}]}.
2013-04-10 21:29:02 -07:00
2013-06-05 21:47:54 +00:00
httpd_start( Port, Module ) ->
2014-01-17 05:32:22 +00:00
Arguments = [{bind_address, "localhost"}, {port, Port}, {ipfamily, inet},
{modules, [Module]},
{server_name,erlang:atom_to_list(Module)}, {server_root,"."}, {document_root,"."}],
{ok, Pid} = inets:start( httpd, Arguments, stand_alone ),
Pid.
2013-06-05 21:47:54 +00:00
httpd_stop( Pid ) ->
2014-01-17 05:32:22 +00:00
inets:stop( stand_alone, Pid ).
2013-04-10 21:29:02 -07:00
2013-06-05 21:47:54 +00:00
task() ->
2014-01-17 05:32:22 +00:00
Pid = httpd_start( 8080, ?MODULE ),
timer:sleep( 30000 ),
httpd_stop( Pid ).