I am trying to use netty through clojure. I can start the server, however it cannot initialize the received socket. The following are error messages and code respectively. Does anyone know what may or may be wrong? I believe the problem is with (Channels/pipeline (server-handler))
Thanks.
Error message
#<NioServerSocketChannel [id: 0x01c888d9, /0.0.0.0:843]> Jun 6, 2012 12:15:35 PM org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink WARNING: Failed to initialize an accepted socket. java.lang.IllegalArgumentException: No matching method found: pipeline
project.clj
(defproject protocol "1.0.0-SNAPSHOT" :description "Upload Protocol Server" :dependencies [ [org.clojure/clojure "1.2.1"] [io.netty/netty "3.4.5.Final"]])
core.clj
(ns protocol.core (:import (java.net InetSocketAddress) (java.util.concurrent Executors) (org.jboss.netty.bootstrap ServerBootstrap) (org.jboss.netty.channel Channels ChannelPipelineFactory SimpleChannelHandler) (org.jboss.netty.channel.socket.nio NioServerSocketChannelFactory) (org.jboss.netty.buffer ChannelBuffers))) (def policy "<content>Test</content>") (defn server-handler "Returns netty handler." [] (proxy [SimpleChannelHandler] [] (messageReceived [ctx e] (let [ch (.getChannel e)] (.write ch policy) (.close ch))) (channelConnected [ctx e] (let [ch (.getChannel e)] (.write ch policy) (.close ch))) (exceptionCaught [ctx e] (let [ex (.getCause e)] (println "Exception" ex) (-> e .getChannel .close))))) (defn setup-pipeline "Returns channel pipeline." [] (proxy [ChannelPipelineFactory] [] (getPipeline [] (Channels/pipeline (server-handler))))) (defn startup "Starts netty server." [port] (let [channel-factory (NioServerSocketChannelFactory. (Executors/newCachedThreadPool) (Executors/newCachedThreadPool)) bootstrap (ServerBootstrap. channel-factory)] (.setPipelineFactory bootstrap (setup-pipeline)) (.setOption bootstrap "child.tcpNoDelay" true) (.setOption bootstrap "child.keepAlive" true) (.bind bootstrap (InetSocketAddress. port))))
source share