                             (cons emdocs-after-change-lambda
                                   after-change-functions))
                 (add-hook 'kill-buffer-hook #'emdocs-disconnect)
-                (add-hook 'kill-emacs-hook #'emdocs-kill-server)))))
+                (add-hook 'kill-emacs-hook #'emdocs-kill-server)
+                (emdocs-broadcast-buffer-at-intervals buffer)))))
       (message "Not connected to internet: exiting.")
       (setq emdocs-mode nil)
       (emdocs-disconnect))))
 
-(defun emdocs-connect ()
+(defun emdocs-connect (buffer)
   "docstring"
   (setq emdocs-ip-addr (read-from-minibuffer "ip: "))
   ;; check for private ips

            (define-key map (kbd "C-c C-c") 'emdocs-mode)
            map)
  (if emdocs-mode
      (emdocs-connect)
    (emdocs-disconnect)))

(provide 'emdocs-mode)

               (emdocs-connect-client buffer ip)))
            (cur-point
             (with-current-buffer buffer
               (when emdocs-mode
                 (save-excursion
                   (setq emdocs-is-network-insert t)
                   (unwind-protect
                       (cond
                        ((string-equal "insert" type)
                         (goto-char cur-point)
                         (insert content))
                        ((string-equal "delete" type)
                         (goto-char cur-point)
                         (delete-char content)))
                     (setq emdocs-is-network-insert nil))))))
            (buffer-contents
             (with-current-buffer buffer
               (when emdocs-mode
                 (let ((prev-point (point)))
                   (setq emdocs-is-network-insert t)
                   (unwind-protect
                       (progn
                         (goto-char (point-min))
                         (erase-buffer)
                         (insert buffer-contents)
                         (goto-char prev-point))
                     (setq emdocs-is-network-insert nil))))))))))

(defun emdocs-connect-client (buffer ip)
  "docstring"
