Created
July 26, 2019 14:37
-
-
Save MattBlack85/8edb5291c0090890a47760f756b7c3ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'usocket) | |
(defun end-string (string how-many) | |
(let ((str-length (length string))) | |
(if (or (< str-length how-many) | |
(not string)) | |
string | |
(subseq string (- str-length how-many) str-length)))) | |
(defun read-lines (connection) | |
(let ((body nil) | |
(temp "some")) | |
(loop while temp | |
do | |
(format t "BODY:~%~a~%" body) | |
(if (string= (end-string body 4) "\r\n\r\n") | |
(progn | |
(format t "Equal~%---------------------~%") | |
body) | |
(progn | |
(format t "Not equal~%------------------------~%") | |
(setq temp (read-line (usocket:socket-stream connection) nil '(\#Return\#linefeed))) | |
(setq body (concatenate 'string body temp '(#\Newline)))))) | |
(format t "Final Body: ~a~%" body))) | |
(defun start-simple-server (port) | |
"Listening on a port for a message, and print the received message." | |
(usocket:with-socket-listener (socket "127.0.0.1" port :reuse-address t) | |
(usocket:wait-for-input socket) | |
(usocket:with-connected-socket (connection (usocket:socket-accept socket)) | |
(read-lines connection) | |
(format (usocket:socket-stream connection) "OK")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment