What's the different between the Java and Clojure code? -


eventloopgroup bossgroup = new nioeventloopgroup(); // (1) eventloopgroup workergroup = new nioeventloopgroup(); try {     serverbootstrap b = new serverbootstrap(); // (2)     b.group(bossgroup, workergroup)             .channel(nioserversocketchannel.class) // (3)             .childhandler(new channelinitializer<socketchannel>() { // (4)                 @override                 public void initchannel(socketchannel ch) throws exception {                     ch.pipeline().addlast(                             new 6messagedecoder(),                             new loginhandler());                 }             })             .option(channeloption.so_backlog, 128             )          // (5)             .childoption(channeloption.so_keepalive, true); // (6)      // bind , start accept incoming connections.     channelfuture f = b.bind(port).sync(); // (7)      // wait until server socket closed.     // in example, not happen, can gracefully     // shut down server.     f.channel().closefuture().sync(); } {     workergroup.shutdowngracefully();     bossgroup.shutdowngracefully(); } 

i write in clojure:

(let [bossgroup (nioeventloopgroup.)       workergroup (nioeventloopgroup.)       bootstrap (serverbootstrap.)]   (.. bootstrap       (group bossgroup workergroup)       (channel nioserversocketchannel)       (childhandler         (proxy [channelinitializer] []              (initchannel [ch]                (.. ch                    (pipeline)                    (addlast                      (messagedecoder.)                      (loginhandler.)                      ))                )))       (option channeloption/so_backlog, (int 128))       (childoption channeloption/so_keepalive, true)       (bind (int 8080))       (sync)       (channel)       (closefuture)       (sync)       ;(childhandler (channelinitializer<socketchannel>.))       )   ) 

the code written in clojure can run,but when test it:

telnet 127.0.0.1 8080 trying 127.0.0.1... connected localhost. escape character '^]'. connection closed foreign host. 

it doesn't work. however, java code can work. what's wrong it?

got reason: in clojure java's variable arguments not supported.(from point of view.) so, (addlast (messagedecoder.) (loginhandler.) ) not correct syntax call

addlast(channelhandler... handlers) ` 

netty complains " method not found",but catches exception , prints warning use log4j.i had not seen warnning before because log4j not configured.

the out put:

escape character '^]'. 

means binding , listenning worked.

now worked code:

(.addlast                  (.pipeline ch)                  (doto (make-array  channelhandler 2)                    (aset 0 (messagedecoder.))                    (aset 2 (serverhandler.))                    )                  ) 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -