retroforth/example/socket-server.forth
crc aab0b6bf18 add initial socket examples: client, server
FossilOrigin-Name: 706122b5c2fc0fabeb0f694820e56963763a5855f1dcacb65c887151c106482f
2019-06-06 17:20:03 +00:00

31 lines
443 B
Forth

Get a socket.
~~~
socket:create 'Sock var<n>
~~~
Bind to port 9998.
~~~
'9998 @Sock socket:bind drop
~~~
Prepare to listen for connections.
~~~
#3 @Sock socket:listen drop-pair
~~~
Serve the user some data. This will repeat 5 times, then end.
~~~
#5 [ @Sock socket:accept (discard_error_code: drop )
'Hello_from_RETRO\n s:format swap [ socket:send drop-pair ] sip socket:close
] times
~~~
Clean up.
~~~
@Sock socket:close
~~~