我们可以基于google talk开发一个属于自己的聊天客户端
代码如下:
public class GoogleTalk {
/**
* @param args
* @throws XMPPException
*/
public static void main(String[] args) throws XMPPException {
XMPPConnection.DEBUG_ENABLED = true;
XMPPConnection connection = new XMPPConnection("gmail.com");
connection.connect();
connection.login("用户名", "密码");
Chat chat = connection.getChatManager().createChat(
"你要进行聊天的用户的ID", new MessageListener() {
public void processMessage(Chat chat, Message message) {
System.out.println(message.getFrom() + " "
+ "说:"
+ message.getBody());
}
});
BufferedReader cmdIn = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
try {
String cmd = cmdIn.readLine();
if ("!q".equalsIgnoreCase(cmd)) {
break;
}
chat.sendMessage(cmd);
} catch (Exception ex) {
}
}
connection.disconnect();
System.exit(0);
}
}
将代码中的中文说明部分替换成你自己的信息就可以