From 092760560b01a4d4a7b7bbf6c603f7ad021731c1 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 9 May 2019 20:18:21 +0200 Subject: [PATCH] Add server example --- server/server-example.lisp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server/server-example.lisp diff --git a/server/server-example.lisp b/server/server-example.lisp new file mode 100644 index 0000000..c9a131b --- /dev/null +++ b/server/server-example.lisp @@ -0,0 +1,34 @@ +(ql:quickload "usocket") +(ql:quickload "babel") + + +(defparameter buf (make-array 10 + :element-type '(unsigned-byte 8) + :adjustable nil + :fill-pointer nil + :displaced-to nil + :initial-element 0)) + ;(defparameter s (usocket:socket-listen "localhost" 8080)) + +(defparameter su (usocket:socket-connect nil nil :protocol :datagram :local-host "localhost" :local-port 8080)) + +;; (defun display-buf (buf) +;; (let* ((message (flexi-streams:octets-to-string buf :external-format :utf-8 :end 10)) +;; (trimmed-message (trim message))) +;; (format t "~a" trimmed-message))) + + + +(defun process (sock) + (multiple-value-bind (recv size remote-host remote-port) + (usocket:socket-receive su buf 10) + (format t "~a" (babel:octets-to-string buf :encoding :utf-8)) + (usocket:socket-send sock buf 10 :host remote-host :port remote-port))) + + + + +(defun again () + (loop + (loop for sock in (usocket:wait-for-input `(,su) :ready-only t) + do (process sock))))