This repository contains an easy-to-use and well-documented .NET assembly for communicating with an XMPP server. It supports basic Instant Messaging and Presence funtionality as well as a variety of XMPP extensions.
You can download this package from NuGet
Artalk Xmpp is an easy-to-use and well-documented .NET assembly for communicating with an XMPP server. It supports basic Instant Messaging and Presence funtionality as well as a variety of XMPP extensions.
The library fully implements the XMPP Core and XMPP Im specifications and thusly provides the basic XMPP instant messaging (IM) and presence functionality. In addition, the library offers support for most of the optional protocol extensions. More specifically, the following features are supported:
The project is hosted at GitHub and can be found at https://github.com/araditc/Artalk.Xmpp. You can always get the latest binary package on Nuget . The documentation is also available for offline viewing as HTML or CHM .
This library is released under the MIT License. It can be used in private and commercial projects.
Please send your bug reports to bugs@arad-itc.org or create a new issue on the GitHub project homepage.
About XMPP
This section provides a brief overview of the architecture of the Extensible Messaging and Presence Protocol (XMPP).
The Extensible Messaging and Presence Protocol (XMPP) is an open XML-based protocol for near-real-time messaging, presence, and request-response services.
The protocol was originally named Jabber, and was developed by the Jabber open-source community in 1999 for near real-time, instant messaging (IM), presence information, and contact list maintenance. Designed to be extensible, the protocol has also been used for publish-subscribe systems, signalling for VoIP, video, file transfer, gaming, Internet of Things applications such as the smart grid, and social networking services.
The XMPP network uses a client–server architecture (clients do not talk directly to one another). However, it is decentralized—by design, there is no central authoritative server, as there is with services such as AOL Instant Messenger or Windows Live Messenger.
Clients send and receive messages only to and from their respective server and it is the server's responsibility to route appropriately-addressed messages through the network to the intended user. For this purpose, every user on the network has a unique Jabber ID (usually abbreviated as JID ). To avoid requiring a central server to maintain a list of IDs, the JID is structured like an email address with a username and a domain name for the server where that user resides, separated by an at sign (@), such as username@example.com.
The following diagram provides a general overview of the XMPP architecture:
This quick start shows you how to incorporate the َArtalk.Xmpp assembly into your application.
You can now start using the namespaces exposed by the Artalk.Xmpp assembly.
This section provides a brief overview of the different namespaces and classes exposed by the Artalk.Xmpp assembly.
The Artalk.Xmpp.Core namespace contains basic client-side components that provide a general framework for exchanging structured information in the form of XML data elements between any two network endpoints and correlates closely to the Extensible Messaging and Presence Protocol (XMPP): Core specification (RFC 3920).
As such, the classes of the Artalk.Xmpp.Core namespace provide building blocks for creating custom communication protocols based on the core XMPP concepts of XML streams and XML stanzas.
The Artalk.Xmpp.Im namespace contains components that implement the basic instant messaging (IM) and presence functionality defined in the Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence specification (RFC 3921).
In other words, Artalk.Xmpp.Im provides a lean "bare bones" XMPP client that implements the minimum feature set that is expected from a conforming implementation. It can be used in situations where a full-scale implementation with support for various XMPP protocol extensions is not neccessary, and can also be used as a basis for creating XMPP clients that implement only a select set of extensions.
The Artalk.Xmpp.Client namespace contains components that built on-top the classes of the Artalk.Xmpp.Im and the Artalk.Xmpp.Core namespaces to implement a feature-rich XMPP client.
The following example demonstrates how to connect to an XMPP server using the ArtalkXmppClient class.
If you already have an account on the server to which you want to connect, establishing a connection is as easy as initializing a new instance of the ArtalkXmppClient class und calling the Connect method as demonstrated in the following example application:
using Artalk.Xmpp.Client;
using System;
using System.Text.RegularExpressions;
namespace ArtalkTest {
class Program {
static void Main(string[] args) {
string hostname = "artalk.ir";
string username = "myusername";
string password = "mysecretpassword";
using (ArtalkXmppClient client = new ArtalkXmppClient(hostname, username, password)) {
// Setup any event handlers.
// ...
client.Connect();
Console.WriteLine("Type 'quit' to exit.");
while (Console.ReadLine() != "quit");
}
}
}
}
client.SendMessage(recipient, message);
Using the constructor of the ArtalkXmppClient class as in the example above will automatically negotiate TLS/SSL encryption if the server supports it, however this behaviour can be disabled by passing the constructor a value of false for the tls parameter.
The following example demonstrates how to set up event handlers for the events exposed by the ArtalkXmppClient class.
The ArtalkXmppClient class exposes a variety of events that can be subscribed to in order to be notified of the receipt of new chat messages, status changes of a chat contact, incoming authorization requests, etc. The following piece of example code shows how to hook up to the Message event in order to be notified of the receipt of new chat-messages:
using Artalk.Xmpp.Client;
using System;
namespace ArtalkTest {
class Program {
static void Main(string[] args) {
string hostname = "artalk.ir";
string username = "myusername";
string password = "mypassword";
using (XmppClient client = new XmppClient(hostname, username, password)) {
// Setup any event handlers before connecting.
client.Message += OnNewMessage;
// Connect and authenticate with the server.
client.Connect();
Console.WriteLine("Type 'quit' to exit.");
while (Console.ReadLine() != "quit");
}
}
/// <summary>
/// Invoked whenever a new chat-message has been received.
/// </summary>
static void OnNewMessage(object sender, MessageEventArgs e) {
Console.WriteLine("Message from <" + e.Jid + ">: " + e.Message.Body);
}
}
}
Whenever a chat-message is sent to myusername@artalk.ir, the OnNewMessage method will be invoked. The MessageEventArgs parameter contains information about the sender of the message as well its content.
Event handlers are invoked sequentially on a separate thread.
You should not call blocking methods from within event handlers and you must not directly update UI controls from within an event handler. Rather, you should call the Invoke method of the respective UI control to have the control updated on the thread that owns the control's underlying window handle.