I wanted to test the speed of sending a file directly from memory. I grabbed a page off wikipedia, it is about 500k. I compile it as a static resource, as part of a simple app that listens on a ServerSocket and sends the page to any client that connects.
If I compile this code and run it on localhost then everything works fine. I can launch this at the command line, get it running on port 3457, and then point my browser at port 3457, and I see the article.
Then I decided to give it a real world test. I rent 2 servers in the Rackspace cloud. I uploaded this app to one server and, again, started it at the command line, this time at port 40000 (no particular reason for that port, I also tried ports 9000 and 6000). Then I ssh to the other server and, from there, I ping the first server with wget. And I get constant problems with "connection reset by peer".
(defn create-server [s]
(while (not (. s (isClosed)))
(let [client (. s accept)]
(start-thread #(let [wrt (new PrintWriter (new BufferedWriter (new OutputStreamWriter (. client (getOutputStream)))))]
(serve-page wrt client)
(catch SocketException e
(. System/out (println "Caught: " (.getMessage e)))
(catch IOException ioe
(. System/out (println "Caught: " (.getMessage ioe)))
(defn -main [& args]
(println "Server is starting")
(let [port (Integer/parseInt (first args))
ss (new ServerSocket port)]
(println "port: " port)
(catch SocketException se
(. System/out (println "Caught: " (.getMessage se)))
In an attempt to find the problem, I have started wrapping everything in exceptions. But none of these exceptions ever print out at the command line, either because there are no exceptions or because the app no longer writes to stdout after it is running.