   [opts]
   (let [opts (merge {:host "127.0.0.1"
                      :port 2003
+                     :protocol :tcp
                      :path graphite-path-percentiles} opts)
         pool (fixed-pool
-               (fn open []
+               (fn []
                  (info "Connecting to " (select-keys opts [:host :port]))
-                 (let [sock (Socket. (:host opts) (:port opts))
-                       out  (OutputStreamWriter. (.getOutputStream sock))]
+                 (let [host (:host opts)
+                       port (:port opts)
+                       client (open (condp = (:protocol opts)
+                                      :tcp (GraphiteTCPClient. host port)
+                                      :udp (GraphiteUDPClient. host port)))]
                    (info "Connected")
-                   [sock out]))
-               (fn close [[sock out]]
+                   client))
+               (fn [client]
                  (info "Closing connection to "
                        (select-keys opts [:host :port]))
-                 (.close out)
-                 (.close sock))
+                 (prn client)
+                 (close client))
                {:size                 (:pool-size opts)
                 :block-start          (:block-start opts)
                 :regenerate-interval  (:reconnect-interval opts)})

  "Forwards events to Graphite."
  (:refer-clojure :exclude [replace])
  (:import
   (java.net Socket)
   (java.io Writer
            OutputStreamWriter)
   (org.jboss.netty.channel Channels)


    (fn [event]
      (when (:metric event)
        (with-pool [client pool (:claim-timeout opts)]
                   (let [string (str (join " " [(path event)
                                                (float (:metric event))
                                                (int (:time event))])
                                     "\n")]
                     (prn "sending " client string)
                     (send! client string)))))))
