躺在沙灘上的小豬

          快樂的每一天

          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 閱讀(253) 評論(0)  編輯  收藏

          主站蜘蛛池模板: 新乡县| 大足县| 浦东新区| 莱阳市| 枞阳县| 噶尔县| 闽侯县| 台南县| 洛隆县| 海伦市| 河曲县| 孙吴县| 宿迁市| 九江县| 铁力市| 额济纳旗| 宿州市| 太白县| 丽江市| 吉林市| 惠来县| 容城县| 阳东县| 家居| 昭通市| 城市| 福建省| 仪陇县| 方山县| 肥城市| 韶山市| 图木舒克市| 呼和浩特市| 德兴市| 曲靖市| 衡阳市| 西峡县| 睢宁县| 长丰县| 赣榆县| 苍山县|