2017-03-21 9 views
1

Javaを使用してsmack 4.1からXEP 198(ストリーム管理)を使用する方法、いくつかの参考文献を共有してください。Smackを使用してストリーム管理をJavaで実装する方法は?

私はここストリーム管理を実装する方法を、2つのクライアントでスパークからピシャリと一方から他方をチャットすることができていますこれにより

private static String username = "test"; 
     private static String password = "test123"; 

     public static class MessageParrot implements PacketListener { 
      private XMPPConnection xmppConnection; 

      public MessageParrot(XMPPConnection conn) { 
       xmppConnection = conn; 
      } 

      public void processPacket(Packet packet) { 
       Message message = (Message)packet; 
       if(message.getBody() != null) { 
        String fromName = StringUtils.parseBareAddress(message.getFrom()); 
        System.out.println("Message from " + fromName + "\n" + message.getBody() + "\n"); 
        Message reply = new Message(); 
        reply.setTo(fromName); 
        reply.setBody("I am a Java bot. You said: " + message.getBody()); 
        xmppConnection.sendPacket(reply); 
       } 
      } 
     } 


     public static void main(String[] args) { 




      System.out.println("Starting IM client"); 

      // gtalk requires this or your messages bounce back as errors 
      ConnectionConfiguration connConfig = new ConnectionConfiguration("domain.com", 5222); 
      XMPPConnection connection = new XMPPConnection(connConfig); 

      try { 
       connection.connect(); 
       System.out.println("Connected to " + connection.getHost()); 
      } catch (XMPPException ex) { 
       //ex.printStackTrace(); 
       System.out.println("Failed to connect to " + connection.getHost()); 
       System.exit(1); 
      } 
      try { 
       connection.login(username, password); 
       System.out.println("Logged in as " + connection.getUser()); 

       Presence presence = new Presence(Presence.Type.available); 

       connection.sendPacket(presence); 

      } catch (XMPPException ex) { 
       //ex.printStackTrace(); 
       // XMPPConnection only remember the username if login is succesful 
       // so we can''t use connection.getUser() unless we log in correctly 
       System.out.println("Failed to log in as " + username); 
       System.exit(1); 
      } 

      PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 
      connection.addPacketListener(new MessageParrot(connection), filter); 

      /* if(args.length > 0) {*/ 
       // google bounces back the default message types, you must use chat 
       Message msg = new Message("[email protected]", Message.Type.chat); 
       msg.setBody("hi"); 
       // msg.addExtension(new DeliveryReceipt(msg.getPacketID())); 

       /* XHTMLExtension xhtmlExtension = new XHTMLExtension(); 
       xhtmlExtension.addBody(
       "<body>My lord, dispatch; read o'er these articles.</body><request xmlns='urn:xmpp:receipts'/>"); 
       msg.addExtension(xhtmlExtension);*/ 


       /* MessageEventManager.addNotificationsRequests(msg, true, true, true, true); 
       DeliveryReceiptManager.addDeliveryReceiptRequest(msg);*/ 
       connection.sendPacket(msg); 


      System.out.println("Press enter to disconnect\n"); 

      try { 
       System.in.read(); 
      } catch (IOException ex) { 
       //ex.printStackTrace(); 
      } 

      connection.disconnect(); 
     } 

を刺激するためにピシャリからメッセージを送信するためにJavaコードを使用していますか?接続オブジェクトこの後

connection.setUseStreamManagement(true); 
connection.setUseStreamManagementResumptionDefault(true); 

を作成した後にコードの下

答えて

0

使用すると、クライアントがストリーム管理を使用したい意味<enable xmlns='urn:xmpp:sm:3' resume='true'/>のログをチェックしてくださいです。サーバーはこれに応答します(サポートされている場合)<enabled xmlns='urn:xmpp:sm:3' id='.......' resume='true' max='1'/>これはストリームが現在有効になっていることを意味します。

ログが常に確認されると、クライアントとサーバーの間で交換が発生します。

関連する問題