Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Created July 18, 2010 23:50
Show Gist options
  • Save jasonm23/480826 to your computer and use it in GitHub Desktop.
Save jasonm23/480826 to your computer and use it in GitHub Desktop.
(defconst client-process-name "*client*")
(defsubst client-process () (get-process client-process-name))
(defun chomp (str)
(if (and (stringp str) (string-match "\r?\n$" str))
(replace-match "" t nil str)
str))
(defun client-notify-connect (&rest args)
(message (format "Connection message [%s]" (mapcar #'chomp args))))
(defun client-open (host port)
(make-network-process :name client-process-name
:host host
:service port
:nowait t
:sentinel #'client-notify-connect)
(sit-for 1))
(defun client-close ()
(delete-process (client-process)))
(defun client-send-string (str)
(process-send-string (client-process) (concat str "\r\n")))
;; Test the client with something like this...
(progn
(client-open 'local 8080)
(dotimes (var 10)
(client-send-string (format "Hello %s" var))
(insert (format "Hello %s\n" var)))
(client-close))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment