Guest User

Untitled

a guest
Jul 11th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'rubygems'
  3. require 'eventmachine'
  4.  
  5. module ConnClient
  6. include EM::P::ObjectProtocol
  7.  
  8. # Called after the connection with a client has been established
  9. def connection_completed
  10. send_data "#{$username}:#{$password}"
  11. end
  12.  
  13. def receive_data data
  14. puts data
  15. end
  16.  
  17. def unbind
  18. puts "connection has terminated"
  19. exit
  20. end
  21. end
  22.  
  23. module KeyboardHandler
  24. def initialize(client)
  25. @client = client
  26. end
  27.  
  28. def receive_data(data)
  29. @client.send_data(data)
  30. end
  31. end
  32.  
  33. $username = ARGV[0]
  34. $password = ARGV[1]
  35.  
  36. if $username && $password
  37. # Start a server on localhost, using port 8081 and hosting our Chat application
  38. EventMachine::run do
  39. client = EventMachine::connect "localhost", 8081, ConnClient
  40. EventMachine::open_keyboard(KeyboardHandler, client)
  41. end
  42. else
  43. puts 'usage: chat username password'
  44. end
Add Comment
Please, Sign In to add comment