mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
848ba7303b
FossilOrigin-Name: b5feea667d30aac255d1cfca61fed355d438d2ce6021677f1e53af6302b15eee
29 lines
924 B
Text
29 lines
924 B
Text
This implements a simple socket based server for RFC865, the "Quote of
|
|
the Day Protocol".
|
|
|
|
~~~
|
|
'Socket var
|
|
|
|
{{
|
|
'Sock var
|
|
'Quote var
|
|
:if-failed swap [ 'ERROR:_ s:put s:put nl bye ] &drop choose ;
|
|
:bind n:to-string @Sock socket:bind drop 'binding_to_port if-failed ;
|
|
:listen #5 @Sock socket:listen drop 'preparing_socket if-failed ;
|
|
:accept @Sock socket:accept n:-zero? 'accept_failed if-failed ;
|
|
:send '_ [ store ] sip @Socket socket:send drop-pair ;
|
|
:remap &send &c:put set-hook ;
|
|
:unmap &c:put unhook ;
|
|
:process [ remap !Socket @Quote call reset unmap ] sip socket:close ;
|
|
---reveal---
|
|
:server:for-each-connection (nq-)
|
|
!Quote socket:create !Sock
|
|
bind listen repeat accept process again ;
|
|
}}
|
|
~~~
|
|
|
|
A test case, sending a message and the time to the user.
|
|
|
|
~~~
|
|
#9999 [ here '/etc/motd file:slurp here s:put ] server:for-each-connection
|
|
~~~
|