Sending chat to Google Talk in Java
In this post , we will see that how to integrate Google Talk(Most popular chat client) with Java Code.
Follow these steps to integrate Google talk with Java
Before start please download the following library and add it in your class path
Note:-This code will only send chat, it is not able to receive msg
![]() |
|
package com.simplecode.chat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.ConnectionConfiguration;
public class GtalkChat {
private static String username = "[email protected]";
private static String password = "XXXXXXX";
ConnectionConfiguration connConfig;
XMPPConnection connection;
public GtalkChat() throws XMPPException
{
connConfig = new ConnectionConfiguration("talk.google.com", 5222,"gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
connection.login(username, password);
}
public void sendMessage(String to, String message)
{
Message msg = new Message(to, Message.Type.chat);
msg.setBody(message);
connection.sendPacket(msg);
}
public void disconnect()
{
connection.disconnect();
}
public static void main(String[] args) throws XMPPException
{
GtalkChat gtalkChat = new GtalkChat();
gtalkChat.sendMessage("[email protected]",
"Hai this message is send using Java with Google talk integration :P ");
gtalkChat.disconnect();
}
}



