Created
July 18, 2010 23:50
-
-
Save jasonm23/480826 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
(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