Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'bundler'
- Bundler.setup
- require 'eventmachine'
- require 'thin'
- class EchoServer < EM::Connection
- def receive_data(data)
- if data.strip =~ /exit$/i
- EventMachine.stop
- else
- send_data(data)
- end
- end
- end
- t1 = Thread.new do
- EventMachine.run do
- EventMachine.start_server("0.0.0.0", 10000, EchoServer)
- end
- end
- t2 = Thread.new do
- Thin::Server.start("0.0.0.0", 11000, signals: false) do
- run ->(env) { [200, {}, 'this is my app!'] }
- end
- end
- # hit Control + C to stop
- Signal.trap("INT") { EventMachine.stop }
- Signal.trap("TERM") { EventMachine.stop }
- puts "Servers booted"
- t1.join
- t2.join
- puts "Servers shut down"
Add Comment
Please, Sign In to add comment