Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'rubygems'
- require 'eventmachine'
- module ConnClient
- include EM::P::ObjectProtocol
- # Called after the connection with a client has been established
- def connection_completed
- send_data "#{$username}:#{$password}"
- end
- def receive_data data
- puts data
- end
- def unbind
- puts "connection has terminated"
- exit
- end
- end
- module KeyboardHandler
- def initialize(client)
- @client = client
- end
- def receive_data(data)
- @client.send_data(data)
- end
- end
- $username = ARGV[0]
- $password = ARGV[1]
- if $username && $password
- # Start a server on localhost, using port 8081 and hosting our Chat application
- EventMachine::run do
- client = EventMachine::connect "localhost", 8081, ConnClient
- EventMachine::open_keyboard(KeyboardHandler, client)
- end
- else
- puts 'usage: chat username password'
- end
Add Comment
Please, Sign In to add comment