The Extensible Messaging and Presence Protocol (XMPP) is a network protocol that uses XML to exchange structured data between two or more network connected entities in near-real-time. XMPP was created to satisfy the IETFs guidelines for instant messaging and presence protocols (RFC 2779), but its purpose goes far beyond IM. It is also used as a message-oriented middleware, for machine-to-machine (M2M) communication and for the Internet of Things (IoT).
The lightweight XMPP core protocol provides users with
The extensible approach makes it possible to build custom protocols on top of XMPP core.
The core XMPP protocol is defined in RFC 6120 and is managed by the Internet Engineering Task Force (XMPP). The instant messaging extensions are defined in RFC 6121, and a third document (RFC 7622) defines the format of XMPP addresses, also called "Jabber Identifiers" (JIDs). Additional functionality is specified in the form of XMPP Extension Protocols (XEPs), which are created by the community and maintained by the XMPP Standards Foundation (XSF).
Version | Notes | Release Date |
---|---|---|
1.0 | Core: RFC 6120, IM: RFC 6121, Address: RFC 7622 | 2011-03-01 |
0.9 | Core: RFC 3920, IM: RFC 3921, Address: RFC 6122 | 2004-10-01 |
import sleekxmpp
client = sleekxmpp.Client("[email protected]", "password")
client.connect()
client.process(blocking=False)
client.send_message(mto="[email protected]", mbody=self.msg)
XMPPTCPConnection connection = new XMPPTCPConnection("user", "password", "example.org")
connection.connect().login();
Message message = new Message("[email protected]", "Hi, how are you?");
connection.sendStanza(message);
connection.disconnect();
public void OpenXmppConnection(int port, bool useSsl, string serverJid, string userName, string password)
{
try
{
_xmppClientConnection.AutoResolveConnectServer = true;
_xmppClientConnection.Port = port;
_xmppClientConnection.UseSSL = useSsl;
_xmppClientConnection.Server = serverJid;
_xmppClientConnection.Username = userName;
_xmppClientConnection.Password = password;
_xmppClientConnection.Resource = "web";
//authenticate and open connection with server
_xmppClientConnection.Open();
}
catch (Exception ex)
{
}
}
Smack (Java)
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
public void sendMessage() {
XMPPTCPConnectionConfiguration config =
XMPPTCPConnectionConfiguration.builder()
.setServiceName("mydomain.local")
.setHost("127.0.0.1")
.setPort(5222)
.build();
XMPPTCPConnection connection = new XMPPTCPConnection(config);
connection.connect();
connection.login("test1", "test1pwd");
ChatManager chatManager = ChatManager.getInstanceFor(connection);
String test2JID = "[email protected]";
Chat chat = chatManager.createChat(test2JID);
chat.sendMessage("Hello, how are you?");
connection.disconnect();
}
public class ConversationManager
{
#region ClassMemeber
private XmppClientConnection _xmppClientConnection = null;
public ConversationManager(XmppClientConnection con)
{
_xmppClientConnection = con;
}
public void SendMessage(string message, string to, string guid, string type)
{
try
{
if (_xmppClientConnection != null)
{
Jid jidTo = new Jid(to);
agsXMPP.protocol.client.Message mesg = new agsXMPP.protocol.client.Message(jidTo, _ConnectionWrapper.MyJid,
agsXMPP.protocol.client.MessageType.chat,
message);
mesg.Id = guid;
mesg.AddChild(new agsXMPP.protocol.extensions.msgreceipts.Request());//request delievery
_xmppClientConnection.Send(mesg);
}
}
catch (Exception ex)
{
}
}
}