Skip to content

Instantly share code, notes, and snippets.

@MattBlack85
Created July 26, 2019 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattBlack85/8edb5291c0090890a47760f756b7c3ab to your computer and use it in GitHub Desktop.
Save MattBlack85/8edb5291c0090890a47760f756b7c3ab to your computer and use it in GitHub Desktop.
(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