200: def initialize(host, port=5222)
201: @id = 1
202: @host = host
203: @port = port
204: @roster = Roster.new(self)
205: @messageListeners = Hash.new
206: @iqHandlers=Hash.new
207: @subscriptionHandler = nil
208: @connection = Jabber::Protocol::Connection.new(host, port)
209: @connection.connect
210: unless @connection.is_connected?
211: raise "Session Error: Could not connected to #{host}:#{port}"
212: else
213: @connection.send(Jabber::Protocol.gen_open_stream(host)) do |element|
214: if element.element_tag=="stream:stream"
215: element.consume_element
216: @session_id = element.attr_id
217: end
218: end
219: @connection.on_connection_exception do
220: if @session_failure_block
221: self.release
222: @session_failure_block.call
223: end
224: end
225: Thread.stop
226: end
227: end