\ server.f
needs sock.f
0 value sock
: server-init ( -- )
8003 sock-create dup to sock
dup -1 = if abort" Unable to make socket!" then
5 sock sock-listen ;
: serve
begin
sock sock-accept?
if sock sock-accept drop
dup s" Server Hello! " rot sock-write drop
dup get-local-time time-buf >time" rot sock-write drop
10 ms sock-close drop
then
10 ms key? until ;
: server ( -- ) server-init serve ;
server
\ client.f
needs sock.f
0 value sock
create tbuf 256 allot
\ client side
: client ( hostname -- )
8003 sock-open
to sock
begin 10 ms
sock sock-read? dup
if pad swap sock sock-read pad swap type else drop then
sock sock-closed?
until
sock sock-close
drop
;
s" 127.0.0.1" client