diff options
author | Case Duckworth | 2023-04-11 11:32:19 -0500 |
---|---|---|
committer | Case Duckworth | 2023-04-11 11:32:19 -0500 |
commit | af43060e1c93d5a4050a4730fecb0803753c8535 (patch) | |
tree | 679fac0d0c2167b70f39001780092d40a67c1b21 | |
parent | Add link to protocol in readme (diff) | |
download | postcard-af43060e1c93d5a4050a4730fecb0803753c8535.tar.gz postcard-af43060e1c93d5a4050a4730fecb0803753c8535.zip |
-rw-r--r-- | .dir-locals.el | 4 | ||||
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | mailbox.scm | 9 | ||||
-rw-r--r-- | postcard.scm | 14 | ||||
-rw-r--r-- | readme.txt | 12 |
5 files changed, 53 insertions, 7 deletions
diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..9c78ce8 --- /dev/null +++ b/.dir-locals.el | |||
@@ -0,0 +1,4 @@ | |||
1 | ;;; Directory Local Variables -*- no-byte-compile: t -*- | ||
2 | ;;; For more information see (info "(emacs) Directory Variables") | ||
3 | |||
4 | ((scheme-mode . ((geiser-scheme-implementation . chicken)))) | ||
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db1bb6c --- /dev/null +++ b/Makefile | |||
@@ -0,0 +1,21 @@ | |||
1 | # postcard | ||
2 | |||
3 | CSC = csc | ||
4 | PREFIX = /usr | ||
5 | PROGS = postcard mailbox | ||
6 | |||
7 | .SUFFIXES: | ||
8 | .SUFFIXES: .scm .o | ||
9 | |||
10 | all: $(PROGS) | ||
11 | |||
12 | .scm: | ||
13 | $(CSC) -o $@ $< | ||
14 | |||
15 | .PHONY: install clean | ||
16 | |||
17 | install: $(PROGS) | ||
18 | install -Dt $(DESTDIR)$(PREFIX)/bin $? | ||
19 | |||
20 | clean: | ||
21 | -rm -f $(PROGS) *.o | ||
diff --git a/mailbox.scm b/mailbox.scm index 948804c..82eaaad 100644 --- a/mailbox.scm +++ b/mailbox.scm | |||
@@ -1,6 +1,7 @@ | |||
1 | ;; server bit | 1 | ;; server bit |
2 | 2 | ||
3 | (import udp) | 3 | (import udp |
4 | utf8) | ||
4 | 5 | ||
5 | (define host "localhost") | 6 | (define host "localhost") |
6 | (define port 42069) | 7 | (define port 42069) |
@@ -9,11 +10,11 @@ | |||
9 | (define s (udp-open-socket)) | 10 | (define s (udp-open-socket)) |
10 | (udp-bind! s #f port) | 11 | (udp-bind! s #f port) |
11 | (let loop ((s s)) | 12 | (let loop ((s s)) |
12 | (receive (len str) (udp-recv s 512) | 13 | (receive (len str host port) (udp-recvfrom s 512) |
13 | (when (= len 0) | 14 | (when (= len 0) |
14 | (loop s)) | 15 | (loop s)) |
15 | (display str) | 16 | (print host ":" port "(" len ")\t" str) |
16 | (newline) | 17 | (udp-sendto s host port (string-append "received: " str)) |
17 | (loop s)))) | 18 | (loop s)))) |
18 | 19 | ||
19 | (main) | 20 | (main) |
diff --git a/postcard.scm b/postcard.scm index 5e54178..7c1eed6 100644 --- a/postcard.scm +++ b/postcard.scm | |||
@@ -1,13 +1,21 @@ | |||
1 | ;; client bit | 1 | ;; client bit |
2 | 2 | ||
3 | (import udp | 3 | (import srfi-13 |
4 | udp | ||
5 | utf8 | ||
4 | (chicken process-context)) | 6 | (chicken process-context)) |
5 | 7 | ||
6 | (define host "localhost") | 8 | (define host "95.216.214.66") |
7 | (define port 42069) | 9 | (define port 42069) |
8 | 10 | ||
9 | (define (main args) | 11 | (define (main args) |
10 | (define s (udp-open-socket)) | 12 | (define s (udp-open-socket)) |
11 | (udp-sendto s host port (apply string-append args))) | 13 | (udp-bind! s #f 0) ; automatically allocate one |
14 | (udp-sendto s host port (string-join args " ")) | ||
15 | (let loop ((s s)) | ||
16 | (receive (len str host port) (udp-recvfrom s 512) | ||
17 | (when (= len 0) | ||
18 | (loop s)) | ||
19 | (print host ":" port "\t" str)))) | ||
12 | 20 | ||
13 | (main (command-line-arguments)) | 21 | (main (command-line-arguments)) |
diff --git a/readme.txt b/readme.txt index a3b0ad1..96f2933 100644 --- a/readme.txt +++ b/readme.txt | |||
@@ -12,3 +12,15 @@ that's it ... for now. | |||
12 | oh, the port is 42069 for the time being and uh, it's just over localhost byeeeee | 12 | oh, the port is 42069 for the time being and uh, it's just over localhost byeeeee |
13 | 13 | ||
14 | (for a description of the protocol, see <https://git.acdw.net/postcard/tree/protocol.txt>) | 14 | (for a description of the protocol, see <https://git.acdw.net/postcard/tree/protocol.txt>) |
15 | |||
16 | --- | ||
17 | |||
18 | programs | ||
19 | |||
20 | server, listens to ports and handles incoming postcards: postoffice | ||
21 | |||
22 | client: | ||
23 | - send: postcard | ||
24 | - check: postbox | ||
25 | - admin: postmaster | ||
26 | |||