aboutsummaryrefslogtreecommitdiff
path: root/server/server-example.lisp
blob: c9a131b6e16c4a94940363f99c20661b2d1ce141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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))))