躺在沙灘上的小豬

          快樂的每一天

          Smack Quick Start

          Smack is a library for communicating with XMPP servers to perform instant messaging and chat.
           

          package cn.martin.xmpp;

          import org.jivesoftware.smack.GroupChat;
          import org.jivesoftware.smack.XMPPConnection;
          import org.jivesoftware.smack.XMPPException;
          import org.jivesoftware.smack.Chat;
          import org.jivesoftware.smack.packet.Message;
          import org.junit.BeforeClass;
          import org.junit.Test;
          import org.junit.AfterClass;

          /**
           * 
          @author martin
           
          */
          public class SmackTest {
              
          private static XMPPConnection con;

              @BeforeClass
              
          public static void getConnection() throws XMPPException {
                  con 
          = new XMPPConnection("rabbit");
                  con.login(
          "martinx""1234");
              }

              @Test
              
          public void chatWithSingle() throws XMPPException {
                  con.createChat(
          "martin@rabbit").sendMessage("Simple Message");
              }

              @Test
              
          public void chatWithGroup() throws XMPPException {
                  String room 
          = "dd@conference.rabbit";
                  GroupChat groupChat 
          = con.createGroupChat(room);
                  groupChat.join(
          "martinx");
                  Message message 
          = groupChat.createMessage();
                  message.setBody(
          "Group Chat Test");
                  groupChat.sendMessage(message);
              }

              @Test
              
          public void chatWithReturnedMessage() throws XMPPException {
                  Chat chat 
          = con.createChat("martin@rabbit");

                  Message message 
          = chat.createMessage();
                  message.setBody(
          "Hello Martin");
                  message.setProperty(
          "favoriteColor""red");
                  chat.sendMessage(message);

                  
          //獲取回復
                  while (true) {
                      Message _message 
          = chat.nextMessage();
                      chat.sendMessage(_message.getBody());
                  }
              }

              @AfterClass
              
          public static void closeConnection() {
                  con.close();
              }
          }

          看了http://forum.javaeye.com/viewtopic.php?t=19089很是感興趣,想做一個,明天繼續

          posted on 2006-03-15 18:24 martin xus 閱讀(255) 評論(0)  編輯  收藏

          主站蜘蛛池模板: 定陶县| 延川县| 杂多县| 娱乐| 玉溪市| 泰来县| 德州市| 黄平县| 葵青区| 娱乐| 东光县| 额尔古纳市| 茶陵县| 荔浦县| 汉源县| 湖北省| 凤翔县| 广安市| 清丰县| 泰州市| 曲周县| 陕西省| 遂川县| 华安县| 泽普县| 团风县| 漾濞| 平原县| 威宁| 华安县| 富顺县| 原平市| 丰城市| 通海县| 玉门市| 大庆市| 江都市| 明水县| 东辽县| 九台市| 繁峙县|