use of de.pixart.messenger.xml.TagWriter in project Pix-Art-Messenger by kriztan.
the class XmppConnection method startXmpp.
/**
* Starts xmpp protocol, call after connecting to socket
*
* @return true if server returns with valid xmpp, false otherwise
*/
private boolean startXmpp(Socket socket) throws Exception {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
this.socket = socket;
tagReader = new XmlReader();
if (tagWriter != null) {
tagWriter.forceClose();
}
tagWriter = new TagWriter();
tagWriter.setOutputStream(socket.getOutputStream());
tagReader.setInputStream(socket.getInputStream());
tagWriter.beginDocument();
sendStartStream();
final Tag tag = tagReader.readTag();
return tag != null && tag.isStart("stream");
}
use of de.pixart.messenger.xml.TagWriter in project Pix-Art-Messenger by kriztan.
the class XmppConnection method disconnect.
public void disconnect(final boolean force) {
interrupt();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": disconnecting force=" + Boolean.valueOf(force));
if (force) {
forceCloseSocket();
} else {
final TagWriter currentTagWriter = this.tagWriter;
if (currentTagWriter.isActive()) {
currentTagWriter.finish();
final Socket currentSocket = this.socket;
final CountDownLatch streamCountDownLatch = this.mStreamCountDownLatch;
try {
currentTagWriter.await(1, TimeUnit.SECONDS);
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": closing stream");
currentTagWriter.writeTag(Tag.end("stream:stream"));
if (streamCountDownLatch != null) {
if (streamCountDownLatch.await(1, TimeUnit.SECONDS)) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": remote ended stream");
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": remote has not closed socket. force closing");
}
}
} catch (InterruptedException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": interrupted while gracefully closing stream");
} catch (final IOException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": io exception during disconnect (" + e.getMessage() + ")");
} finally {
FileBackend.close(currentSocket);
}
} else {
forceCloseSocket();
}
}
}
Aggregations