Guest User

Untitled

a guest
Jul 11th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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 post_init
  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. $username = ARGV[0]
  24. $password = ARGV[1]
  25.  
  26. if $username && $password
  27. # Start a server on localhost, using port 8081 and hosting our Chat application
  28. EventMachine::run do
  29. EventMachine::connect "localhost", 8081, ConnClient
  30. end
  31. else
  32. puts 'usage: chat username password'
  33. end
Add Comment
Please, Sign In to add comment