So, this started when I read Keith Swallow's article on a simple web server:

http://keithcelt.com/a-simple-web-server-in-clojure

I took his code and ran "lein new" to create a new project and I copy and 
pasted his code to core.clj and made some minor adjustments, adding 
gen-class and main so I could run this from the command line. My main 
function looked like this: 

(defn -main [& args]
  (let [port (Integer/parseInt (first args))]
    (println "Server is starting")
    (run-server port echo)))

Which called his function: 

(defn run-server [port service]
  (let [server-socket (create-socket port)]
    (while (not (. server-socket isClosed)) 

      (listen-and-respond server-socket service)))) 

I compiled that and ran "lein uberjar" and then ran it from the command 
line and it worked great. 

Then, to make it slightly more flexible, I wanted to hand in the name of 
the service from the command line. So I made a minor change: 


(defn run-server [port what-to-do]
  (let [server-socket (ServerSocket. "localhost" port)]
    (while (not (. server-socket isClosed))
      (listen-and-respond server-socket what-to-do))))

(defn -main [& args]
  (let [port (Integer/parseInt (first args))
        service (second args)]
    (println "Server is starting")
    (println "port: " port)
    (println "service: " service)
    (run-server port service)))

I compiled this and ran it. And now this line: 

(defn run-server [port what-to-do]

Gets this error: 

Exception in thread "main" java.lang.ClassCastException: java.lang.String 
cannot be cast to java.lang.Number
at who_is_logged_in.core$run_server.invoke(core.clj:27)

I'm calling it from the command line with: 

java -jar who-is-logged-in-1.0.0-SNAPSHOT-standalone.jar 3456 
who-is-here-now

I also tried putting the service name in quotes: 

java -jar who-is-logged-in-1.0.0-SNAPSHOT-standalone.jar 3456 
"who-is-here-now"

Can anyone tell me what is wrong? Why does Clojure think I'm trying to cast 
"who-is-here-now" to a number? 



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to