For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket.

Catching any exceptions or errors is not required.




needs sockets
 
#! A simple abstraction layer that makes writing trivial servers easy
value| server.socket server.connection server.action |
[ ( n- )   pBind to server.socket ] is server.setSocket
[ ( - )    server.socket pAccept to server.connection ] is server.acceptConnection
[ ( - )    server.connection pClose drop ] is server.closeConnection
[ ( $- )   >r server.connection r> string.getLength pWrite drop ] is server.send
[ ( an- )  server.connection -rot pRead drop ] is server.recieve
[ ( qn- )  swap to server.action server.setSocket
  [ server.acceptConnection server.action invoke server.closeConnection TRUE ] whileTrue ] is server.start
 
#! The actual server
[ " hello socket world" server.send ] 256 server.start