(defun maintain-connection-input () "Creates a contantly listening server for the device to connect to, on *tcp-port-input*, this function also sets the value of *remote-peer-ip* for use with (create-output-connection). the value of tcp-in-socket comes from the calling function" (declare (ignorable tcp-in-socket)) (setf tcp-in-socket (establish-tcp-listen *tcp-port-input*)) (handler-case (unwind-protect (loop (let* ((accepted (usocket:socket-accept tcp-in-socket)) (rpi (usocket:get-peer-name accepted))) (format *standard-output* "~%Remote PEER ~A~%" rpi) (unless (null rpi) (setf *REMOTE-PEER-IP* rpi)) (let ((stream (usocket:socket-stream (usocket:wait-for-input accepted)))) (when stream (let ((json (json:decode-json stream))) (format *standard-output* "~%json: ~A~%" json) (push-q *input-commands-queue* json)))))) (usocket:socket-close tcp-in-socket)) (END-OF-FILE (condition) (format *standard-output* "~%EOF: ~A~%" condition) (maintain-connection-input)))) ;;I want to ignore the compiler complaining about tcp-in-socket being undefined ; caught WARNING: ; undefined variable: TCP-IN-SOCKET ; ; compilation unit finished ; Undefined variable: ; TCP-IN-SOCKET ; caught 1 WARNING condition ; caught 1 STYLE-WARNING condition ;;the variable is defined in the function that calls the above (defun do-thread () (unwind-protect (progn (let ((tcp-out-socket nil) (tcp-in-socket nil) (udp-in-socket nil)) (declare (ignore tcp-out-socket tcp-in-socket udp-in-socket)) (setf *REMOTE-PEER-IP* nil) (setf *udp-port* nil) (setf *tcp-port-output* nil) (unless (null *REMOTE-SERVER-CONNECTION-STREAM*) (usocket:socket-close *remote-server-connection-stream*) (setf *remote-server-connection-stream* nil)) (setf bt:*default-special-bindings* (acons '*standard-output* *standard-output* bt:*default-special-bindings*)) (bt:make-thread #'maintain-connection-input :name "TCP-RECEIVE-THREAD") (find-and-do-command-input))) (kill-my-threads)))