建立自己的IM与GTALK通信计算机等级考试

文章作者 100test 发表时间 2010:01:01 12:16:41
来源 100Test.Com百考试题网


  自己的上网环境需要代理,上网处理smack代理的资源没有是正常的,只有寥寥几个记载,并且是设置java环境的网络代理,设置了在smack上还是不行的。后面实在不行了,看看api,原来本身就有支持的废话小讲直接贴代码
  view plaincopy to clipboardprint?
  public class Test {
  public static void main(String[] args) throws XMPPException, IOException{
  XMPPConnection.DEBUG_ENABLED = true.
  ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com",5222,"gmail.com").
  ProxyInfo proxy = ProxyInfo.forHttpProxy("代理地址", 8080, null, null).//代理服务器设置 这里用http代理的 具体看网络环境
  //使用新的socket工厂
  config.setSocketFactory(proxy.getSocketFactory()).
  XMPPConnection conn = new XMPPConnection(config).
  conn.connect().
  conn.login("[email protected]", "xxxxx").
  Chat chat = conn.getChatManager().createChat("[email protected]", new MessageListener(){
  //接收信息
  @Override
  public void processMessage(Chat chat, Message message) {
  System.out.println(message.getFrom() ":" message.getBody()).
  }
  }).
  //监听键盘输入 发送信息
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in)).
  String line = null.
  while((line = br.readLine()) != null){
  if(line.equals(":q")){
  break.
  }
  chat.sendMessage(line).
  }
  conn.disconnect().
  System.exit(0).
  }
  }
  public class Test {
  public static void main(String[] args) throws XMPPException, IOException{
  XMPPConnection.DEBUG_ENABLED = true.
  ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com",5222,"gmail.com").
  ProxyInfo proxy = ProxyInfo.forHttpProxy("代理地址", 8080, null, null).//代理服务器设置 这里用http代理的 具体看网络环境
  //使用新的socket工厂
  config.setSocketFactory(proxy.getSocketFactory()).
  XMPPConnection conn = new XMPPConnection(config).
  conn.connect().
  conn.login("[email protected]", "xxxxx").
  Chat chat = conn.getChatManager().createChat("[email protected]", new MessageListener(){
  //接收信息
  @Override
  public void processMessage(Chat chat, Message message) {
  System.out.println(message.getFrom() ":" message.getBody()).
  }
  }).
  //监听键盘输入 发送信息
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in)).
  String line = null.
  while((line = br.readLine()) != null){
  if(line.equals(":q")){
  break.
  }
  chat.sendMessage(line).
  }
  conn.disconnect().
  System.exit(0).
  }
  }

  编辑特别推荐:

  ·计算机等级考试二级JAVA考前密卷及参考答案
  ·全国计算机等级考试二级JAVA全真模拟试题
  ·全国计算机等级考试二级JAVA在线模拟考试
  ·计算机等级考试二级Java初级练习(精选25题)



相关文章


JAVA性能优化—IBMJDKJVM参数设置计算机等级考试
JAVA序列化的两种方式计算机等级考试
关于jar包中MANIFEST.MF的问题计算机等级考试
实现Comparator接口来进行字符串逆向排序计算机等级考试
建立自己的IM与GTALK通信计算机等级考试
利用delegate调试Ajax应用计算机等级考试
最值得学习的五种JAVA技术计算机等级考试
30个JAVA的基本概念计算机等级考试
java字符串的各种编码转换计算机等级考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛