建立自己的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题)