I use Smack API to write my Google talk Client . Now i need to handle add request for this . I set SubscriptionMode to manual & now I have to registering a listener for presence packets but i don't know how !! can any body help ?
I've tried it yet, But I guess the below should work. If using the manual mode, a PacketListener should be registered that listens for Presence packets that have a type of Presence.Type.subscribe.
First set the roster to
Roster roster = connection.getRoster();
roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
Then add a packet listner to the above connection eg :
connection.addPacketListener(new SubscriptionListener(), new PacketFilter(){
public boolean accept(Packet packet) {
if(packet instanceof Presence)
if(((Presence)packet).getType().equals(Presence.Type.subscribe))
return true;
return false;
}});
The above code just returns true for all requests, But you can customize it i.e set it to true or false based on user GUI input.
Hello everyone sir i want to talk to gmail but my code doesnot run sucessfully it throws run time exception
java.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202) at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:272) at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:276) at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:122) at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212) at java.io.BufferedWriter.flush(BufferedWriter.java:236) at org.jivesoftware.smack.util.ObservableWriter.flush(ObservableWriter.java:48) at org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:274) at org.jivesoftware.smack.PacketWriter.access$000(PacketWriter.java:40) at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:87) java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) at java.io.InputStreamReader.read(InputStreamReader.java:167) at java.io.BufferedReader.read1(BufferedReader.java:185) at java.io.BufferedReader.read(BufferedReader.java:261) at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:42) at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2992) at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046) at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410) at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395) at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093) at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:368) at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44) at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)
what can be the problem plz reply me soon