diff --git a/README.md b/README.md index 07e7f2b..625b0d2 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,71 @@ Last updated: September 23, 2025 (PRH). ```bash zx run erltris ``` + + +## Notes + +### Big Picture: telnet chat server -> HTTP server + +- The default project (see initial commit) is a telnet echo server. It's like + the most ghetto low-budget chat server imaginable. + + ![screenshot of `gh_httpd` running](./etc/gh-telnet.png) + + Lefty and middley can chat just like normal. + + However, righty (`curl`) foolishly thinks he is talking to an HTTP server. + His request is echoed to lefty and middley. + + Curl crashed because instead of a valid HTTP response back, he got something + like + + ``` + MESSAGE from YOU: GET / HTTP/1.1 + ``` + +- We make this into an HTTP server by replacing the "echo my message to + everyone else" logic with "parse this message as an HTTP request and send + back an HTTP response" logic. +- Our "application logic" or "business logic" or whatever is contained in that + process of how the request is mapped to a response. +- It really is not more complicated than that. + +### Basics of Erlang Processes + +These are heuristics that are good starting points + +- each module ~= 1 process +- it helps to think of erlang as an operating system, and erlang modules as + shell scripts that run in that operating system. +- some modules correspond to fungible processes, some are non-fungible +- in Observer (`observer:start()`) + - named processes are non-fungible (e.g. `gh_client_sup`) + - the name can be anything, but conventionally it's the module name + - fungible processes have numbers (PIDs) (e.g. the `gh_client` code) + - named processes also have PIDs, they just also have names + + ![](./etc/observer.png) + + +### Following the call chain of `gex_httpd:listen(8080)` + +- Reference commit: `49a09d192c6f2380c5186ec7d81e98785d667214` +- By default, the telnet server doesn't occupy a port +- `gex_httpd:listen(8080)` tells it to listen on port 8080 + +``` +%% gex_httpd.erl +-spec listen(PortNum) -> Result + when PortNum :: inet:port_num(), + Result :: ok + | {error, {listening, inet:port_num()}}. +%% @doc +%% Make the server start listening on a port. +%% Returns an {error, Reason} tuple if it is already listening. + +listen(PortNum) -> + gh_client_man:listen(PortNum). + + +%% diff --git a/etc/gh-telnet.png b/etc/gh-telnet.png new file mode 100644 index 0000000..9d6ff19 Binary files /dev/null and b/etc/gh-telnet.png differ diff --git a/etc/observer.png b/etc/observer.png new file mode 100644 index 0000000..b1078bd Binary files /dev/null and b/etc/observer.png differ