小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

一個gtalk的robot的簡單實現(xiàn)...

 shaobin0604@163.com 2007-05-28
package jj.chen;
/*
* 本程序用到了www.的smack api
* 如果大家對googletalk有興趣可以去以上網(wǎng)站自己下一個api
* 祝愿googletalk一路走好!
*/
import java.io.Serializable;
import java.util.Collection;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.GoogleTalkConnection;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
public class Test implements Serializable {

/**
*
*/
private static final long serialVersionUID = -5102956900764101510L;

/**
* @param args
* @throws XMPPException
* @throws XMPPException
*/
public static void main(String[] args) throws XMPPException {
// TODO Auto-generated method stub


final GoogleTalkConnection con = new GoogleTalkConnection();
con.login("jjchen831", "123456");//googletalk的 用戶名, 密碼
System.out.println("===========1");


Presence presence = new Presence(Presence.Type.AVAILABLE);
con.sendPacket(presence);


System.out.println("===============2");


final Roster roster = con.getRoster();
roster.addRosterListener(new RosterListener() {
public void presenceChanged(String user) {
// If the presence is unavailable then "null" will be printed,
// which is fine for this example.
System.out.println("Presence changed: "
+ roster.getPresence(user));


if(roster.getPresence(user)!=null){
final Chat chat=con.createChat(user);
try {

chat.sendMessage("hello");//給每個在線人說hello

chat.addMessageListener(new PacketListener(){

public void processPacket(Packet arg0) {
// TODO Auto-generated method stub
System.out.println("PacketListener");
Message message=chat.nextMessage(); //得到別人給你的信息

try {
f(message.getBody().equals("help")){
//如果別人給你的信息是help
chat.sendMessage("thank you for test robot!");
//就發(fā)給他thank you for test robot!
}else{
chat.sendMessage(" please enter help ");
//如果別人發(fā)給你的信息不是help就發(fā)給他 please enter help
}
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

});
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
system.out.println(user+"++++++++");
}

}

public void entriesAdded(Collection arg0) {
// TODO Auto-generated method stub
System.out.println("entriesAdded");
}

public void entriesUpdated(Collection arg0) {
// TODO Auto-generated method stub
System.out.println("entriesUpdated");
}

public void entriesDeleted(Collection arg0) {
// TODO Auto-generated method stub
System.out.println("entriesDeleted");
}
});
System.out.println("===============3");


while(true){
try {
Thread.sleep(500000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多