close

(This is a repost of an old blog post of mine from Teknik.)

#common-lisp #usocket #networking

CL-USER> (ql:quickload :usocket)
To load "usocket":
  Load 1 ASDF system:
    usocket
; Loading "usocket"
[package usocket]..........
(:USOCKET)
CL-USER> (use-package :usocket)
T
CL-USER> (defvar *server* (socket-listen "127.0.0.1" 65432))
*SERVER*
CL-USER> (defvar *client-1* (socket-connect "127.0.0.1" 65432))
*CLIENT-1*
CL-USER> (defvar *client-2* (socket-accept *server*))
*CLIENT-2*
CL-USER> (print "hello world!" (socket-stream *client-1*))
"hello world!"
CL-USER> (finish-output (socket-stream *client-1*))
NIL
CL-USER> (read-line (socket-stream *client-2*))
""
NIL
CL-USER> (socket-close *client-1*)
T
CL-USER> (socket-close *client-2*)
T
CL-USER> (socket-close *server*)
T