1.2.0 permalink Arrow_down_16x16
  • (create-server port fun backlog bind-addr)
  • (create-server port fun backlog)
  • (create-server port fun)
Creates a server socket on port. Upon accept, a new thread is
created which calls:

(fun input-stream output-stream)

Optional arguments support specifying a listen backlog and binding
to a specific endpoint.

1 Example top

  • ;; A Simple server that dumps the input stream to the output stream.
    ;; In this example, the create-server function is called with two
    ;; arguments, a port number and an anonymous function. The input
    ;; and output stream arguments passed to the anonymous function are
    ;; bound to the standard input and output respectively.
    
    (use 'clojure.contrib.server-socket)
    (import  '(java.io BufferedReader InputStreamReader PrintWriter))
    
    user=> (create-server
             8080
             (fn [in out]
               (binding
                 [*in* (BufferedReader. (InputStreamReader. in))
                  *out* (PrintWriter. out)]
                 (loop []
                   (println (read-line))
                   (recur)))))
    
    {:server-socket #<ServerSocket ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=8080]>, :connections #<Ref@73f17a73: #{}>}
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/server_socket.clj:53 top

(defn create-server 
  "Creates a server socket on port. Upon accept, a new thread is
  created which calls:

  (fun input-stream output-stream)

  Optional arguments support specifying a listen backlog and binding
  to a specific endpoint."
  ([port fun backlog ^InetAddress bind-addr] 
     (create-server-aux fun (ServerSocket. port backlog bind-addr)))
  ([port fun backlog]
     (create-server-aux fun (ServerSocket. port backlog)))
  ([port fun]
     (create-server-aux fun (ServerSocket. port))))
Vars in clojure.contrib.server-socket/create-server: defn
Used in 0 other vars

Comments top

No comments for create-server. Log in to add a comment.