I am using this code where i use the smack library to connect to the Google server.But the issue is that i do not know how to keep the code running so that i can keep sending and receiving messages.Please be so kind as to help me with this.I am copy pasting the code :
// connect to gtalk server
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connConfig);
connection.connect();
// login with username and password
connection.login("camel.test.1", "secret");
// set presence status info
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
// send a message to somebody
Message msg = new Message("xxx.xxx@gmail.com", Message.Type.chat);
msg.setBody("hello");
connection.sendPacket(msg);
connection.disconnect();
Please do note that sending message works fine with this code.Let me know of the modifications i need to do in the same code so that i can use it for both sending and receiving messages.
1 Answer