private boolean handleServerStream() throws IOException, XMLStreamException {

		// Get the next XML event
		int eventType = parser.getEventType();
		while (eventType != XMLStreamConstants.END_DOCUMENT) {

			// Check if the parse event is a XML start tag
			if (eventType == XMLStreamConstants.START_ELEMENT) {

				// Case 1: Stream tag
				if (parser.getLocalName().equals("stream")) {
					handleStreamTag();
				}

				// Case 2: Features tag
				else if (parser.getLocalName().equals("features")) {
					handleFeaturesTag();
				}

				// Case 3: Starttls Proceed tag
				else if (parser.getLocalName().equals("proceed")) {
					upgradeToTls();
					// We need to re-send the stream tag after TLS
					return true;
				}

				// Case 4: Authentication Challenge tag
				else if (parser.getLocalName().equals("challenge")) {
					respondToChallenge();
				}

				// Case 5: Authentication Success tag
				else if (parser.getLocalName().equals("success")) {
					handleSuccessTag();
					// We need to re-send the stream tag after SASL
					return true;
				}

				// Case 6: Failure tag (for TLS and SASL)
				else if (parser.getLocalName().equals("failure")) {
					handleFailureTag();
				}

				// Case 7: IQ tag (for resource ID request's response)
				else if (parser.getLocalName().equals("iq")) {
					handleIQTag();

					// Return, we have successfully opened the connection
					return false;
				}
			}

			// Get the next XML event from the parser
			eventType = parser.next();
		}

		// We are done, no need to re-send the stream tag
		return false;
	}