Skip to content

Commit

Permalink
Add mDNS support
Browse files Browse the repository at this point in the history
  • Loading branch information
verma committed Mar 10, 2014
1 parent 2e61093 commit f1cc964
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[org.clojure/data.json "0.2.4"]
[de.ubercode.clostache/clostache "1.3.1"]
[org.clojure/tools.logging "0.2.6"]
[javax.jmdns/jmdns "3.4.1"]
[me.raynes/conch "0.5.0"]
[crate "0.2.5"]
[jayq "2.5.0"]]
Expand Down
5 changes: 5 additions & 0 deletions src/dakait/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
dakait.views
dakait.files
dakait.config
dakait.mdns
[clojure.core.async :only(>! go)]
[dakait.util :only (join-path)]
[dakait.downloader :only (run start-download downloads-in-progress downloads-pending)]
Expand Down Expand Up @@ -130,6 +131,10 @@
(load-tags (str (config :config-data-dir) "/tags.json"))
(load-associations)
(run)
(let [port (System/getenv "PORT")
port (when (nil? port) 3000)]
(println "Starting mDNS server on port:" port)
(publish-service port))
(catch Exception e
(println "Program initialization failed: " (.getMessage e))
(System/exit 1)))
Expand Down
18 changes: 18 additions & 0 deletions src/dakait/mdns.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns dakait.mdns
(:import (javax.jmdns JmDNS
ServiceInfo)))

(def ^{:private true} service (atom nil))

(defn publish-service
"Register a mDNS service with given information"
[port]
(let [service-info (ServiceInfo/create
"_dakait._tcp.local."
"Dakait"
port
"SFTP File download and management utility")
mdns (JmDNS/create)]
(.registerService mdns service-info)
(reset! service mdns)))

0 comments on commit f1cc964

Please sign in to comment.