server & client

9 views
Skip to first unread message

燕南

unread,
Jul 27, 2018, 8:37:21 PM7/27/18
to 符式協會



\ 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







@hotmail.com hcchen_1471

unread,
Jul 30, 2018, 11:28:38 PM7/30/18
to figt...@googlegroups.com, hcche...@yahoo.com.cn
Reply all
Reply to author
Forward
0 new messages