Using the default Erlang installation what is the minimum code needed to produce a "Hello world" producing web server?
相关问题
- Is “new” in Erlang part of the official standard a
- how to create a keep-alive process in Erlang
- ejabberd and Erlang installation with lager_transf
- Encrypt (cryptojs) - Decrypt (erlang)
- How to use erlang-examples
相关文章
- How do I modify a record in erlang?
- Check active timers in Erlang
- undefined function maps:to_json/1
- How to convert datetime() to timestamp() in Erlang
- what good orm api will work well with scala or erl
- GC performance in Erlang
- When to “let it crash” and when to defend the code
- Intercept login/logout ejabberd
Taking "produce" literally, here is a pretty small one. It doesn't even read the request (but does fork on every request, so it's not as minimal possible).
Just one fix for Felix's answer and it addresses the issues Martin is seeing. Before closing a socket, all data being sent from the client should be received (using for example
do_recv
from gen_tcp description).Otherwise there's a race condition for the browser/proxy sending the HTTP request being quick enough to send the http request before the socket is closed.
Another way, similar to the
gen_tcp
example above but with less code and already offered as a suggestion, is using the inets library.Keep in mind, this exposes your
/tmp
directory.To run, simply:
Do you actually want to write a web server in Erlang, or do you want an Erlang web server so that you can create dynamic web content using Erlang?
If the latter, try YAWS. If the former, have a look at the YAWS source code for inspiration
For a web server using only the built in libraries check out inets http_server. When in need of some more power but still with simplicity you should check out the mochiweb library. You can google for loads of example code.
For a very easy to use webserver for building restful apps or such check out the gen_webserver behaviour: http://github.com/martinjlogan/gen_web_server.