     (insert "filter:" msg)
     (unless (bolp) (newline)))
   (let* ((json-object-type 'plist)
-         (json-msg (json-read-from-string msg)))
-    (unless (member (plist-get json-msg :ip) *emdocs-client-connections*)
-      (add-to-list '*emdocs-server-clients*
-                   (cons (plist-get json-msg :buffer) sock))
-      (emdocs-connect-client (plist-get json-msg :buffer)
-                             (plist-get json-msg :ip))
+         (json-msg (json-read-from-string msg))
+         (buffer (plist-get json-msg :buffer))
+         (ip (plist-get json-msg :ip)))
+    (unless (find ip *emdocs-outgoing-clients*
+                  :test #'emdocs-is-ip-from-client)
+      (add-to-list '*emdocs-incoming-clients*
+                   (make-instance 'emdocs-client
+                                  :process sock
+                                  :attached-buffer buffer
+                                  :ip ip))
+      (emdocs-connect-client buffer ip)
       (emdocs-broadcast-message msg))))
 
 (defun emdocs-setup-server (my-ip)

                     (string-match "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" msg)
                     (match-string-no-properties 0 msg))))
           (unless (find ip *emdocs-outgoing-clients*
                         :test (lambda (test-ip client)
                                 (string-equal test-ip
                                               (emdocs-get-ip client))))
             (process-send-string sock "give me buffer and ip\n"))))
        ((string-match "^connection broken by remote peer\n$" msg)
         (setq *emdocs-server-clients*
               (remove-if
                (lambda (item)
                  (equal (car item) sock))
                *emdocs-server-clients*)))))

(defun emdocs-server-filter (sock msg)
  "docstring"


;;; classes

(defclass emdocs-client ()
  ((process
    :initarg :process
    :accessor emdocs-get-process)
   (attached-buffer
    :initarg :attached-buffer
    :accessor emdocs-get-attached-buffer)
   (ip
    :initarg :ip
    :accessor emdocs-get-ip)))

;;; functions
