Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><b>Please find the following code.<br/> Please add smack.jar &amp; smackx.jar to your build path<br/> </b></p> <pre><code>import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; public class GoogleTalkDemo extends Thread{ private XMPPConnection xmppConnection; public void connect(String server, int port, String s) throws Exception { xmppConnection = new XMPPConnection(new ConnectionConfiguration(server, port,s)); xmppConnection.connect(); } public void disconnect(){ if(xmppConnection != null){ xmppConnection.disconnect(); interrupt(); } } public void login(String username, String password) throws Exception{ connect("talk.google.com", 5222, "gmail.com"); xmppConnection.login(username, password); } public void run(){ try { login("youtID@sample.com", "your password"); System.out.println("Login successful"); listeningForMessages(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String args[]) throws Exception { GoogleTalkDemo gtd = new GoogleTalkDemo(); gtd.run(); } public void listeningForMessages() { PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class)); PacketCollector collector = xmppConnection.createPacketCollector(filter); while (true) { Packet packet = collector.nextResult(); if (packet instanceof Message) { Message message = (Message) packet; if (message != null &amp;&amp; message.getBody() != null) System.out.println("Received message from " + packet.getFrom() + " : " + (message != null ? message.getBody() : "NULL")); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload