Skip to content

Instantly share code, notes, and snippets.

@joshbuddy
Created October 13, 2010 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbuddy/623661 to your computer and use it in GitHub Desktop.
Save joshbuddy/623661 to your computer and use it in GitHub Desktop.
import java.net.InetSocketAddress
import java.util.concurrent.Executors
import org.jboss.netty.bootstrap.ServerBootstrap
import org.jboss.netty.channel.ChannelPipelineFactory
import org.jboss.netty.channel.Channels
import org.jboss.netty.channel.SimpleChannelUpstreamHandler
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory
import org.jboss.netty.channel.MessageEvent
class EchoServer
class EchoServerHandler < SimpleChannelUpstreamHandler
def messageReceived(e: MessageEvent)
e.getChannel().write(e.getMessage())
end
end
def initialize(port: fixnum)
channel_factory = NioServerSocketChannelFactory.new(Executors.newCachedThreadPool, Executors.newCachedThreadPool)
Channels.pipeline EchoServerHandler.new
@bootstrap = ServerBootstrap.new(channel_factory)
@bootstrap.setPipelineFactory do
Channels.pipeline EchoServerHandler.new
end
@bootstrap.bind InetSocketAddress.new port
puts "Server ready on port #{port}"
end
end
#
#if __FILE__ == $0
# EchoServer.new 8080
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment