Created
October 13, 2010 08:11
-
-
Save joshbuddy/623661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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