     (cond 
       (= ::external (type @server*)) (osc-send-msg @server* 
                                                    (apply osc-msg path (osc-type-tag args) args))
-      (= ::internal (type @server*))
-      (let [buffer (java.nio.ByteBuffer/allocate 8129)]
-        (World_SendPacket @world* (.limit buffer) buffer
-                          (callback reply-cb (fn [addr buf size] (println "reply!"))))
-      (nil? @server*) (throw (Exception. "Not connected to a SuperCollider server.")))))
+      (= ::internal (type @server*)) (event ::send-osc-message (apply osc-msg path (osc-type-tag args) args))))
 
 (defmacro at
   "Schedule the messages sent in body at a single time."


(def N-RETRIES 50)

(defn- connect-thread 
  [host port]
   (log/debug "Connecting to SuperCollider server: " host ":" port)
   (dosync (ref-set server* (with-meta
                              (osc-client host port)
                              {:type ::external})))

      (recur (inc cnt))))
   (register-notification-handlers))

(defn- connect-thread-internal
  []
   (log/debug "Connecting to internal SuperCollider server")
   (dosync (ref-set server* (with-meta                              
                              {:type ::internal})))
   (loop [cnt 0]
    (when (and (< cnt N-RETRIES)
               (= @status* :booting))
      (snd "/status")
      (when (recv "status.reply" REPLY-TIMEOUT)
        (dosync (ref-set status* :booted))
        (notify true) ; turn on notifications now that we can communicate
        ;(run-boot-handlers)
        )
      (recur (inc cnt))))
   (register-notification-handlers))

; TODO: setup an error-handler in the case that we can't connect to the server
(defn connect
  "Connect to an external SC audio server on the specified host and port."
  ([] (connect :external SERVER-HOST SERVER-PORT))
  ([which & host port]
     (cond 
      (= :internal which) (.run (Thread. #(connect-thread-internal)))
      (= :external which) (.run (Thread. #(connect-thread-external host port))) ))))

(defonce running?* (atom false))

