OpenFire Smack message receipt settings, handling swap issues

Source: Internet
Author: User

In the network instability, openfire prone to swap situations, because when the client dropped the line, OpenFire can not immediately know that the client has been disconnected, as to how long it takes to find the client disconnection, and the server-side set idle Connections time. The default is 360 seconds.

To solve the swap problem, the XMPP protocol supports message receipts, which simply sets the request receipt when the client sends a message, and the server does not need to set it up.

To set the message receipt method using Smack

Package com.penngo.test;import java.awt.eventqueue;public class receiptdialog extends  jdialog {private jtextfield textfield;/** * launch the application.  */public static void main (String[] args)  {eventqueue.invokelater (new  Runnable ()  {public void run ()  {try {ReceiptDialog dialog = new  Receiptdialog ();d ialog.setdefaultcloseoperation (jdialog.dispose_on_close);d ialog.setvisible (true);  catch  (exception e)  {e.printstacktrace ();}});} /** * create the dialog. */public receiptdialog ()  throws Exception{ SetBounds (100, 100, 450, 300); Getcontentpane (). setlayout (NULL);textfield = new  JTextField (); Textfield.setbounds (20, 20, 301, 22); Getcontentpane (). Add (TextField); Textfield.setcolumns (10); connection.debug_enabled = true;  //  OpenSmack debugconnectionconfiguration config = new connectionconfiguration ("127.0.0.1",  5222);//52222config.setsendpresence (True);final connection connection = new  Xmppconnection (config);//  automatically reply to receipts if the message asks for a receipt. Providermanager pm = providermanager.getinstance ();p M.addextensionprovider ( Deliveryreceipt.element, deliveryreceipt.namespace, new deliveryreceipt.provider ());  Pm.addextensionprovider (deliveryreceiptrequest.element, deliveryreceipt.namespace, new  Deliveryreceiptrequest.provider ());D eliveryreceiptmanager.getinstancefor (connection). Enableautoreceipts (); Connection.connect (); String domain = connection.getservicename ();// test1 login, send message to test2//string from =   "Test1";//final string to =  "test2"  +  "@"  + domain;//test2 login, Send a message to test1string from =  "Test2";final string to =  "Test1"  +  "@"  + domain;connection.login (from,  "123456",  "PC");//presence p =  new presence (Presence.Type.available);//p.setmode (mode.chat);//p.setstatus ("online");// Connection.sendpacket (P); Final chat chat = connection.getchatmanager (). CreateChat (To,  null); Jbutton sendbutton = new jbutton ("send"); Sendbutton.addactionlistener (new  ActionListener ()  {public void actionperformed (actionevent e)  {Message message  = new message (); Message.setfrom (Connection.getuser ()); Message.setto (to); Message.setBody ( Textfield.gettext ());D eliveryreceiptmanager.adddeliveryreceiptrequest (message);  //  receipt settings, Request Receipt System.out.println ("Send ======="  + message.toxml ()), try{chat.sendmessage (message); catch (Exception ex) {ex.printstacktrace ();}}}); Sendbutton.setbounds (331, 19, 93, 23); Getcontentpane (). Add (Sendbutton);}}

Run the results and view the data in the Smack debug window

Test2 sends a message to TEST1 with a message ID of Winlh-55


Test1 send receipts to test2, tell Test2 message Winlh-55 has received


OpenFire Smack message receipt settings, handling swap issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.