updating readme
This commit is contained in:
parent
49a09d192c
commit
0b56df873d
68
README.md
68
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.
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
|
||||
### 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).
|
||||
|
||||
|
||||
%%
|
||||
|
||||
BIN
etc/gh-telnet.png
Normal file
BIN
etc/gh-telnet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 219 KiB |
BIN
etc/observer.png
Normal file
BIN
etc/observer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Loading…
x
Reference in New Issue
Block a user