Instantly share code, notes, and snippets.

Embed
What would you like to do?
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