/// <summary> /// Initiates an XML stream with the specified entity. /// </summary> /// <param name="hostname">The name of the receiving entity with which to /// initiate an XML stream.</param> /// <returns>The 'stream:features' XML element as received from the /// receiving entity upon stream establishment.</returns> /// <exception cref="XmlException">The XML parser has encountered invalid /// or unexpected XML data.</exception> /// <exception cref="CultureNotFoundException">The culture specified by the /// XML-stream in it's 'xml:lang' attribute could not be found.</exception> /// <exception cref="IOException">There was a failure while writing to the /// network, or there was a failure while reading from the network.</exception> XmlElement InitiateStream(string hostname) { var xml = Xml.Element("stream:stream", "jabber:client") .Attr("to", hostname) .Attr("version", "1.0") .Attr("xmlns:stream", "http://etherx.jabber.org/streams") .Attr("xml:lang", CultureInfo.CurrentCulture.Name); Send(xml.ToXmlString(xmlDeclaration: true, leaveOpen: true)); // Create a new parser instance. if (parser != null) parser.Close(); parser = new StreamParser(stream, true); // Remember the default language of the stream. The server is required to // include this, but we make sure nonetheless. Language = parser.Language ?? new CultureInfo("en"); // The first element of the stream must be <stream:features>. return parser.NextElement("stream:features"); }
/// <summary> /// Releases all resources used by the current instance of the XmppCore /// class, optionally disposing of managed resource. /// </summary> /// <param name="disposing">true to dispose of managed resources, otherwise /// false.</param> protected virtual void Dispose(bool disposing) { if (!disposed) { // Indicate that the instance has been disposed. disposed = true; // Get rid of managed resources. if (disposing) { if (parser != null) parser.Close(); parser = null; if (client != null) client.Close(); client = null; } // Get rid of unmanaged resources. } }