gtalk:建立自己的IM 和GTALK通信

自己上网环境需要代理,上网处理smack代理资源没有是正常,只有寥寥几个记载,并且是设置java环境网络代理设置了在smack上还是不行后面实在不行了看看api原来本身就有支持(囧 不早点看) 废话小讲 直接贴代码

view plaincopy to clipboardpr?
public Test {
public void (String args) throws XMPPException, IOException{

XMPPConnection.DEBUG_ENABLED = true;
ConnectionConfiguration config = ConnectionConfiguration("talk.google.com",5222,"gmail.com");
ProxyInfo proxy = ProxyInfo.forHttpProxy("代理地址", 8080, null, null);//代理服务器设置 这里用http代理 具体看网络环境
//使用新工厂
config.SocketFactory(proxy.getSocketFactory);

XMPPConnection conn = XMPPConnection(config);

conn.connect;
conn.login("[email protected]", "xxxxx");
Chat chat = conn.getChatManager.createChat("[email protected]", MessageListener{
//接收信息
@Override
public void processMessage(Chat chat, Message message) {
.out.prln(message.getFrom + ":" + message.getBody);
}
});
//监听键盘输入 发送信息
BufferedReader br = BufferedReader( InputStreamReader(.in));
String line = null;
while((line = br.readLine) != null){
(line.equals(":q")){
;
}
chat.sendMessage(line);
}
conn.disconnect;
.exit(0);
}
}
public Test {
public void (String args) throws XMPPException, IOException{

XMPPConnection.DEBUG_ENABLED = true;
ConnectionConfiguration config = ConnectionConfiguration("talk.google.com",5222,"gmail.com");
ProxyInfo proxy = ProxyInfo.forHttpProxy("代理地址", 8080, null, null);//代理服务器设置 这里用http代理 具体看网络环境
//使用新工厂
config.SocketFactory(proxy.getSocketFactory);

XMPPConnection conn = XMPPConnection(config);

conn.connect;
conn.login("[email protected]", "xxxxx");
Chat chat = conn.getChatManager.createChat("[email protected]", MessageListener{
//接收信息
@Override
public void processMessage(Chat chat, Message message) {
.out.prln(message.getFrom + ":" + message.getBody);
}
});
//监听键盘输入 发送信息
BufferedReader br = BufferedReader( InputStreamReader(.in));
String line = null;
while((line = br.readLine) != null){
(line.equals(":q")){
;
}
chat.sendMessage(line);
}
conn.disconnect;
.exit(0);
}
}

上例代码级别来源网上 本人只是对代理部分进行补充 并通过调试 如果原来作者有意见话 请告诉我
Tags:  gtalk注册 googlevoicegtalk gtalk是什么 gtalk

延伸阅读

最新评论

发表评论