Skip to content

Instantly share code, notes, and snippets.

@grafov
Created September 15, 2012 22:50
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 grafov/3730213 to your computer and use it in GitHub Desktop.
Save grafov/3730213 to your computer and use it in GitHub Desktop.
Send current buffer to server:port
(defun tcp-send (server port &optional timeout)
"Отправить текст текущего буфера на server:port"
(if (not timeout) (setq timeout 60))
(let* ((res "*TCP/Result*")
(cur-buf (buffer-name))
(proc (open-network-stream "TcpRequest"
(progn (switch-to-buffer (get-buffer-create res))
(erase-buffer)
(switch-to-buffer cur-buf) res)
server port)))
(process-send-string proc (buffer-string))
(while (equal (process-status proc) 'open)
(when (not (accept-process-output proc timeout))
(delete-process proc)
(error "Network timeout.")))
(switch-to-buffer res)
(beginning-of-buffer)
(split-window)
(switch-to-buffer cur-buf)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment