posts - 495,  comments - 11,  trackbacks - 0

          /*
          * @(#)GtalkTest.java 2010-4-17
          *
          * Copyright (c) 2010 by gerald. All Rights Reserved.
          */

          package org.jsoft.opensource.demos.smack;

          import org.apache.commons.logging.Log;
          import org.apache.commons.logging.LogFactory;
          import org.jivesoftware.smack.Chat;
          import org.jivesoftware.smack.ChatManager;
          import org.jivesoftware.smack.ConnectionConfiguration;
          import org.jivesoftware.smack.MessageListener;
          import org.jivesoftware.smack.XMPPConnection;
          import org.jivesoftware.smack.packet.Message;

          /**
          * 利用Smack,通過XMPP協議與Gtalk通信.
          *
          * @author <a href="
          mailto:gerald.chen@qq.com">GeraldChen</a>
          * @version $Id: GtalkTest.java 2010-4-17 上午12:30:23$
          */
          public class GtalkTest {
          /** Logger for this class */
          protected static final Log LOG = LogFactory.getLog(GtalkTest.class);

          public static void main(String[] args) {
          ?? test();
          }

          /**
          * 與Gtalk進行通訊
          *
          */
          public static void test() {
          ?? ConnectionConfiguration connectionConfig = new ConnectionConfiguration(
          ???? "talk.google.com", 5222, "gmail.com");
          ?? connectionConfig.setSASLAuthenticationEnabled(false);
          ?? XMPPConnection connection = new XMPPConnection(connectionConfig);
          ?? try {
          ??? connection.connect();
          ??? connection.login("logs.chen", "***********");
          ??? ChatManager chatmanager = connection.getChatManager();

          ??? Chat newChat = chatmanager.createChat("edotxp@gmail.com",
          ????? new MessageListener() {
          ?????? public void processMessage(Chat chat, Message message) {
          ??????? if(LOG.isInfoEnabled()) {
          ???????? LOG.info("Received message: \r\n" + message.toXML());
          ???????? LOG.info("收到相應消息");
          ??????? }
          ?????? }
          ????? });
          ??? newChat.sendMessage("陳先生,您好!");
          ??? Thread.sleep(10000);
          ?? } catch (Exception e) {
          ??? LOG.error(e);
          ?? }
          }

          }

          posted on 2010-04-17 02:11 jadmin 閱讀(351) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 布拖县| 黄石市| 汶川县| 武安市| 林周县| 泗水县| 和硕县| 丹江口市| 苏尼特右旗| 刚察县| 栖霞市| 石门县| 晴隆县| 小金县| 芒康县| 南岸区| 荆门市| 新建县| 涿州市| 新竹县| 和田市| 大理市| 钟祥市| 门头沟区| 周至县| 乌兰浩特市| 昌江| 东明县| 涞水县| 漳浦县| 宕昌县| 海伦市| 西平县| 台州市| 乐至县| 犍为县| 房产| 巴马| 三江| 通渭县| 渭源县|