Task

Write a server for a minimal text based chat.

People should be able to connect via ‘telnet’, sign on with a nickname, and type messages which will then be seen by all other connected users. Arrivals and departures of chat members should generate appropriate notification messages.




#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(de chat Lst
   (out *Sock
      (mapc prin Lst)
      (prinl) ) )
 
(setq *Port (port 4004))
 
(loop
   (setq *Sock (listen *Port))
   (NIL (fork) (close *Port))
   (close *Sock) )
 
(out *Sock
   (prin "Please enter your name: ")
   (flush) )
(in *Sock (setq *Name (line T)))
 
(tell 'chat "+++ " *Name " arrived +++")
 
(task *Sock
   (in @
      (ifn (eof)
         (tell 'chat *Name "> " (line T))
         (tell 'chat "--- " *Name " left ---")
         (bye) ) ) )
(wait)