Guest User

Untitled

a guest
Jan 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. require 'bundler'
  2. Bundler.setup
  3.  
  4. require 'eventmachine'
  5. require 'thin'
  6.  
  7. class EchoServer < EM::Connection
  8. def receive_data(data)
  9. if data.strip =~ /exit$/i
  10. EventMachine.stop
  11. else
  12. send_data(data)
  13. end
  14. end
  15. end
  16.  
  17. t1 = Thread.new do
  18. EventMachine.run do
  19. EventMachine.start_server("0.0.0.0", 10000, EchoServer)
  20. end
  21. end
  22.  
  23. t2 = Thread.new do
  24. Thin::Server.start("0.0.0.0", 11000, signals: false) do
  25. run ->(env) { [200, {}, 'this is my app!'] }
  26. end
  27. end
  28.  
  29. # hit Control + C to stop
  30. Signal.trap("INT") { EventMachine.stop }
  31. Signal.trap("TERM") { EventMachine.stop }
  32.  
  33. puts "Servers booted"
  34.  
  35. t1.join
  36. t2.join
  37.  
  38. puts "Servers shut down"
Add Comment
Please, Sign In to add comment