(ql:quickload '(usocket bordeaux-threads)) (defclass client () ((host :initform "127.0.0.1" :initarg :host :accessor host) (port :initform 1234 :initarg :port :accessor port) (socket :initform NIL :accessor socket))) (defmethod connect ((client client)) ;; Connect to the server (let ((socket (usocket:socket-connect (host client) (port client)))) (setf (socket client) socket) (process-connection client socket))) (defmethod process-connection ((client client) socket) (flet ((handler () ;; Read lines as long as the stream is open (loop with stream = (usocket:socket-stream socket) for line = (read-line stream NIL NIL) while line do (format T "~&> ~a~%" line)))) (bt:make-thread #'handler :initial-bindings `((*standard-output* . ,*standard-output*))))) (defmethod broadcast ((client client) line) (let ((stream (usocket:socket-stream (socket client)))) (write-line line stream) (finish-output stream))) (let ((client (make-instance 'client))) (connect client) (loop (broadcast client (read-line))))