   (with-current-buffer (emdocs-get-server-process-buffer)
     (goto-char (point-min))
     (insert "sentinel:" msg)
-    (newline))
+    (unless (bolp) (newline)))
   (cond ((string-match "^open from [0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\n$" msg)
-         (process-send-string sock "give your ip and buffer\n"))))
+         (process-send-string sock "give me buffer and ip")
+         (add-to-list '*emdocs-clients* sock))
+        ((string-match "^connection broken by remote peer\n$")
+         (setq *emdocs-clients* (delete sock *emdocs-clients*)))))
 
 (defun emdocs-server-filter (sock msg)
   "docstring"
+  ;; assumes will only receive json from emdocs-client-sentinel
   (with-current-buffer (emdocs-get-server-process-buffer)
     (goto-char (point-min))
     (insert "filter:" msg)
-    (newline)))
+    (unless (bolp) (newline)))
+  (let* ((json-object-type 'plist)
+         (json-msg (json-read-from-string msg)))
+    (emdocs-connect-client (plist-get json-msg :buffer)
+                           (plist-get json-msg :ip))))
 
 (defun emdocs-setup-server (my-ip)
   "docstring"

                (progn (message "Client could not connect: exiting.")
                       (setq emdocs-mode nil)
                       (emdocs-disconnect))
              (insert "DO AFTER-CHANGE FUNCTIONS"))))
      (message "Not connected to internet: exiting.")
      (setq emdocs-mode nil)
      (emdocs-disconnect))))

        do (when (and client
                      (not (eq client 'no-conn)))
             (delete-process client)))
  (makunbound 'emdocs-client-list)
  (remove-hook 'after-change-functions #'emdocs-after-change-function))

;;; interactives
(defun emdocs-kill-server ()
  "docstring"
  (interactive)
