接口XMPPConnection

接口XMPPConnection

  • 所有已知的实现类:
    AbstractXMPPConnectionXMPPBOSHConnectionXMPPTCPConnection


    公共接口XMPPConnection
    XMPPConnection接口提供用于连接到XMPP服务器的接口,并实现由不同类型的连接(例如XMPPTCPConnectionXMPPBOSHConnection使用的共享方法 要创建与XMPP服务器的连接,此API的简单用法可能如下所示:
     //创建与igniterealtime.org XMPP服务器的连接。
     XMPPTCPConnection con = new XMPPTCPConnection(“igniterealtime.org”);
     //连接到服务器
     con.connect();
     //大多数服务器要求您在执行其他任务之前登录。
     con.login(“jsmith”,“mypass”);
     //与John Doe开始新的对话并向他发送消息。
     ChatManager chatManager = ChatManager.getInstanceFor(con);
     chatManager.addIncomingListener(new IncomingChatMessageListener(){
         public void newIncomingMessage(EntityBareJid from,Message message,Chat chat){
             //打印出我们返回标准的任何消息。
             System.out.println(“收到的消息:”+消息);
         }
     });
     聊天聊天= chatManager.chatWith(“jdoe@igniterealtime.org”);
     chat.send( “你好!”);
     //断开与服务器的连接
     con.disconnect();
     1  // Create a connection to the igniterealtime.org XMPP server.
     2  XMPPTCPConnection con = new XMPPTCPConnection("igniterealtime.org");
     3  // Connect to the server
     4  con.connect();
     5  // Most servers require you to login before performing other tasks.
     6  con.login("jsmith", "mypass");
     7  // Start a new conversation with John Doe and send him a message.
     8  ChatManager chatManager = ChatManager.getInstanceFor(con);
     9  chatManager.addIncomingListener(new IncomingChatMessageListener() {
    10      public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
    11          // Print out any messages we get back to standard out.
    12          System.out.println("Received message: " + message);
    13      }
    14  });
    15  Chat chat = chatManager.chatWith("jdoe@igniterealtime.org");
    16  chat.send("Howdy!");
    17  // Disconnect from the server
    18  con.disconnect();

    需要注意的是XMPPConnection接口并没有故意申报操纵的连接状态,例如任何方法connect()disconnect()您应该使用最具体的连接类型,例如XMPPTCPConnection声明的类型,并在不需要操作连接状态时使用XMPPConnection接口。

    XMPPConnections可以在连接之间重用。这意味着可以连接,断开连接然后再连接。XMPPConnection的监听器将保留在各个连接中。

原文地址:https://www.cnblogs.com/endv/p/11415973.html