socket-samples/README.md

49 lines
1.8 KiB
Markdown
Raw Normal View History

2026-03-26 10:06:21 +00:00
# socket-samples
2026-03-27 20:04:01 +00:00
Socket programming examples in strict C90 and modern Python3.
## Build & Run C90 Examples
```
2026-03-27 20:13:19 +00:00
make clean && make all
2026-03-27 20:04:01 +00:00
```
Builds 9 binaries in `build/` (strict `-std=c90 -pedantic -Wall -Wextra -Werror`).
Port: **9999**
All use the same **custom binary protocol**:
- Header: `1-byte type + 2-byte BE16 length`
- Types: `PING(0x01)`, `PONG(0x02)`, `METRIC_REQ(0x03)`, `METRIC_RESP(0x04)`, `SUBSCRIBE(0x05)`, `PUSH(0x06)`, `UNSUB(0x07)`, `ERROR(0xFF)`
- Metrics: `cpu`, `memory`, `disk`, `loadavg`, `uptime` (simulated)
### C90 Clients
- `src/c90/metric_client.c`: Basic interactive TCP client (ping/get/quit).
- `src/c90/metric_client_ansi.c`: Advanced TCP client w/ `select()` + unsubscribe.
- `src/c90/metric_client_sub.c`: TCP client w/ live subscribe/push via `select()`.
- `src/c90/metric_client_udp.c`: Full-featured UDP client (get/sub/unsub).
- `src/c90/perf_client_udp.c`: UDP perf tester (`--flood` or subscribe mode, 30s throughput).
### C90 Servers
- `src/c90/metric_server.c`: Iterative TCP server (single client).
- `src/c90/metric_server_fork.c`: Forking TCP server (multi-client).
- `src/c90/metric_server_fork_sub.c`: Forking TCP server w/ subscribe/push.
- `src/c90/metric_server_udp.c`: UDP server w/ subscriber management (`select()`).
## Python Examples
2026-03-27 20:17:07 +00:00
Run: `python3 src/python/{file}.py [host [port]]`
2026-03-27 20:04:01 +00:00
Port: **9999** (metrics), **65432** (echo)
### Echo (text protocol)
- `src/python/echo_client.py`: Interactive TCP echo client.
- `src/python/echo_server.py`: Iterative TCP echo server.
### Metrics (same binary protocol as C90)
- `src/python/metric_client.py`: Threaded TCP client (ping/get).
- `src/python/metric_server.py`: Threaded multi-client TCP server.
### Monitor (advanced w/ subscribe/push)
- `src/python/mon_client.py`: Full TCP client (ping/get/sub).
- `src/python/mon_server.py`: Threaded TCP server w/ subscribe/push support.