19 lines
845 B
Common Lisp
19 lines
845 B
Common Lisp
(in-package :remote-snake-server)
|
|
|
|
(defparameter *server-api* (make-instance 'api))
|
|
|
|
;;; Not that max buffer size is important (since snake in on a single line, snake coordinate can be cutted !)
|
|
(defparameter *server-buffer* (make-array 10000
|
|
:element-type '(unsigned-byte 8)
|
|
:initial-element 0))
|
|
|
|
(defun handle-client (buffer) ; echo
|
|
(declare (type (simple-array (unsigned-byte 8) *) buffer)) ; Seems to be to tell lisp which type is buffer
|
|
(let ((request (babel:octets-to-string buffer)))
|
|
(format t "Receive client request: ~a" request)
|
|
(babel:string-to-octets
|
|
(handle-request *server-api* request))))
|
|
|
|
;;; The server :D
|
|
(defun start (host port)
|
|
(usocket:socket-server host port #'handle-client nil :in-new-thread nil :protocol :datagram))
|