xmppClose()
Closes the client communication channel to an XMPP server.
Synopsis
int xmppClose(int clientId);
Parameter
Parameter | Description |
---|---|
clientID | A unique ID for this client channel. The function xmppOpen() returns the clientid. |
Return Value
Returns 0 when the function was successfully executed or a number < 0 in case of errors
Errors
Errors can be queried via getLastError().
Description
Closes the client communication channel to an XMPP server. The client communication channel was opened via the function xmppOpen().
The following example opens the client communication channel to the jabber XMPP server, sends a message and closes the channel.
Note: You have to replace the code:
p =
xmppOpen("winccoa.etm@jabber.at","123677", "callback", m); DebugN("xmppOpen:",
p);
by your own user and password. This code is an example!#uses "CtrlXmpp"
int p;
main(mapping event)
{
mapping m; /* options mapping for the xmppOpen function. */
int port;
string host;
string resource;
bool autoAcceptSubscriptions = TRUE;
string logging;
m["host"]= host;
m["port"] = port;
m["resource"] = resource;
m["autoAcceptSubscriptions"] = autoAcceptSubscriptions;
m["logging"] = "any";
/* Show all debug information (send, receive etc.).
You have to activate the debug flag for the manager that executed the XMPP functions
in order to show the debug info via the logging key. See the function xmppOpen() */
/* Open a client communication channel to an XMPP server. */
p = xmppOpen("winccoa.etm@jabber.at","123677", "callback", m);
DebugN("xmppOpen:", p);
/* Options mapping for sending a message */
mapping mes;
bool attentionRequested = TRUE;
bool receiptRequested = TRUE;
string receiptId;
string thread;
string subject;
time t = getCurrentTime();
mes["attentionRequested"] = attentionRequested;
mes["receiptRequested"] = receiptRequested;
mes["receiptId"] = receiptId;
mes["thread"] = thread;
mes["subject"] = subject;
mes["time"] = t;
string rID;
/* Send the message with options attentionRequested = TRUE and receiptRequested = TRUE
as well as the current time. The other parameters are not specified and thus the default values
are used.*/
int j = xmppSendMessage(p,"winccoa.etm@jabber.at", "Hello this is a new message", mes, rID);
DebugN("Message sent:", j);
}
void callback(mapping message) /* Output the received message */
{
DebugN("Message:", message); //The message
dyn_string keys = mappingKeys(message);
for(int i = 1; i <= dynlen(keys); i++)
{
DebugTN("key: " + keys[i] + " | type: " +getTypeName(message[keys[i]]), "value:",mappingGetValue(message,i));
}
if ( message.receiptRequested )
{
DebugN("Send confirmation to the server:", xmppSendMessage(message.clientId, message.from,"", makeMapping("receiptId", message.id)));
DebugN("Message", message.clientId, "from:", message.from, "sent");
}
/* Close the connection */
int k;
DebugN("Close the connection:", k = xmppClose(p));
}
Assignment
Availability
CTRL