start server, start client, send regions or buffer as code for remote evaluation
;;client and server ;; server functions - receive incoming requests. eval code (defvar prm-process nil) (defvar prmclient-process nil) (defvar the_buffer nil) (defvar host nil) (defvar port nil) (defun prmserv-start (&optional port) (interactive (list (read-string "Serve requests on port: " "8080"))) (if (null port) (setq port 8080) (if (stringp port) (setq port (string-to-number port)))) (if prm-process (delete-process prm-process)) (setq the_buffer (generate-new-buffer "prm")) (setq prm-process (make-network-process :name "prm" :buffer the_buffer :host 'local :service port :server t :noquery t :filter 'prm-serve))) (defun prm-stop () (interactive) (when prm-process (message "prmisc.el server on port %d has stopped" (cadr (process-contact prm-process))) (delete-process prm-process) (setq prm-process nil))) (defun prm-serve (proc string) (let ((prm-process proc)) (switch-to-buffer-other-window the_buffer) (print (eval (read string)) the_buffer))) ;; client functions - initiate connection, send buffer, send region, send last sexp ;; how collab editing could work ?? (defun prmclient-start (&optional port host) (interactive (list (read-string "Send requests on port: " "8080"))) (if (null port) (setq port 8080) (if (stringp port) (setq port (string-to-number port))) (if prmclient-process (delete-process prmclient-process)) (setq prmclient-process (make-network-process :name "prm_client" :host host :service port)))) (defun prm-sendbufferascode() (interactive) ;; (switch-to-buffer the_buffer) (process-send-string "prm_client" (buffer-string))) (defun prm-sendregionascode() (interactive) (save-excursion (save-restriction (narrow-to-region (region-beginning) (region-end)) (process-send-string "prm_client" (buffer-string))))) ;;(prmclient-start 8080 "127.0.0.1") ;;(prmserv-start 8080) ;;(prm-stop) ;;(prm-sendregionascode)
http://xahlee.org/elisp/Network-Processes.html
Referencing httpd.el in earlier iteration we don't have:
(fboundp 'open-network-stream-server) ;; M-x e gives nill
and with ref to later code (emerge htppd, require...):
(featurep 'make-network-process)as in:
(defun httpd-start (&optional port) (interactive (list (read-string "Serve Web requests on port: " "8080"))) (if (null port) (setq port 8080) (if (stringp port) (setq port (string-to-number port)))) (if httpd-process (delete-process httpd-process)) (setq httpd-process (if (fboundp 'make-network-process) (make-network-process :name "httpd" :buffer (generate-new-buffer "httpd") :host 'local :service port :server t :noquery t :filter 'httpd-serve) (and (fboundp 'open-network-stream-server) (open-network-stream-server "httpd" (generate-new-buffer "httpd") port nil 'httpd-serve))))which is not in our 21.4 version... see:
http://xahlee.org/elisp/Antinews.html changelog for those downgrading to 21.4 from 22.0:
Networking has also been simplified: make-network-process and its various associated function have all been replaced with a single easy-to-use function, open-network-stream, which can't use UDP, can't act as a server, and can't set up non-blocking connections. Also, deleting a network process with delete-process won't call the sentinel.
... upgrade or use shell helper a la netcat...
For part one:
http://www.fotokatie.com/katier/?p=170
and part two:
http://www.fotokatie.com/katier/?p=233
with thanks to Katier