Google Talk integration with Java

Sharing is Caring

Hello All

Google Talk is most popular chat client that uses your Gmail login authentication, and after this tutorial, you will be able to create your own Gtalk (if you use swing ), this tutorial shows how to integrate Gtalk with Java.

This example uses Smack API, Smack is an Open Source XMPP (Jabber) client library for instant messaging and presence. A pure Java library, it can be embedded into your applications to create anything from a full XMPP client to simple XMPP integrations such as sending notification messages and presence-enabling devices.


Google Talk

 

  • Code to integrate Google talk with java
 package chat_Server;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
public class GtalkChat {
private static String username = “ashishawasthi000@gmail.com”;
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(“abcdefg@gmail.com”,
“Hii this message is send using Java and Google talk integration.”);
gtalkChat.disconnect();
}
}
  • Change line 7 and line 8 with your username and password respectively
  • Change line 27 with receiver’s email id and type your message
  • Now download SMACK API from its website or click on the link below
  • Extract Smack.rar and Add Smack.jar and Smackx.jar to your project
  • Now run the code
  • This code will only send chat, try to receive using your own code
Cheers 🙂 Happy Learning

Related Posts

2 thoughts on “Google Talk integration with Java”

Leave a Reply

Your email address will not be published. Required fields are marked *