def open_connection
client_opts = { :platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/ruby-amqp/bunny', :version => VERSION }
send_frame(Qrack::Protocol::Connection::StartOk.new(client_opts, 'AMQPLAIN', {:LOGIN => @user, :PASSWORD => @pass}, 'en_US'))
frame = next_frame
raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
method = frame.payload
if method.is_a?(Qrack::Protocol::Connection::Tune)
send_frame(Qrack::Protocol::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
end
send_frame(Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist))
case method = next_method
when Qrack::Protocol::Connection::OpenOk
:ok
when Qrack::Protocol::Connection::Redirect
raise Bunny::ConnectionError, "Cannot connect to the specified server - host: #{@host}, port: #{@port}" if @insist
@host, @port = method.host.split(':')
close_socket
else
raise Bunny::ProtocolError, 'Cannot open connection'
end
end