Shammer's Philosophy

My private adversaria

Lisp UDP Server 改

Lisp UDP Server - Shammerismで残っていた課題を反映させてみた。

(let ((server (make-socket :type :datagram
			   :local-host "0.0.0.0"
			   :local-port 7001
			   :format :binary)))
  (with-open-file (f "/var/log/clozure-udp-server.log" :direction :output :if-exists :append :if-does-not-exist :create)
		  (do () ()
		      (multiple-value-bind (buffer length client-ip client-port)
					   (receive-from server 512)
					   (when (equalp buffer #(81 85 73 84 10))
					     (return))
					   (format f "[~A:~A] Received byte length is ~A, message is ~A~%"
						   (ipaddr-to-dotted client-ip)
						   client-port
						   length
						   (decode-string-from-octets buffer :external-format :UTF-8))
					   (force-output f))))
  (format f "FINISH!~%"))
(quit)