From 44c7c01059640147fbb9df129c2cff7b0a127329 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sat, 3 Aug 2013 19:19:34 +0700 Subject: XMPP library update --- src/com/juick/jabber/ws/Main.java | 43 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/com/juick/jabber/ws/Main.java b/src/com/juick/jabber/ws/Main.java index 32f3e962..dec38586 100644 --- a/src/com/juick/jabber/ws/Main.java +++ b/src/com/juick/jabber/ws/Main.java @@ -18,15 +18,15 @@ package com.juick.jabber.ws; import com.juick.xmpp.JID; -import com.juick.xmpp.MessageListener; -import com.juick.xmpp.XmppConnection; -import com.juick.xmpp.XmppConnectionComponent; -import com.juick.xmpp.XmppListener; +import com.juick.xmpp.Message; +import com.juick.xmpp.Stream; +import com.juick.xmpp.StreamComponent; import com.juick.xmpp.extensions.JuickMessage; import java.io.FileInputStream; import java.io.IOException; import java.math.BigInteger; import java.net.InetSocketAddress; +import java.net.Socket; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.channels.SelectionKey; @@ -48,10 +48,10 @@ import java.util.Properties; * * @author Ugnich Anton */ -public class Main implements XmppListener, MessageListener { +public class Main implements Stream.StreamListener, Message.MessageListener { Connection sql; - XmppConnection xmpp; + Stream xmpp; ArrayList sockReplies = new ArrayList(); ArrayList sockMessages = new ArrayList(); ArrayList sockAll = new ArrayList(); @@ -83,25 +83,26 @@ public class Main implements XmppListener, MessageListener { } public void setupXmppComponent(String password) { - xmpp = new XmppConnectionComponent(new JID("", "ws.juick.com", ""), password, "127.0.0.1", 5347, false); - xmpp.addListener((XmppListener) this); - xmpp.addListener((MessageListener) this); - xmpp.start(); - } - - @Override - public void onConnectionFailed(String msg) { - System.err.println("XMPP onConnFailed " + msg); + try { + Socket socket = new Socket("localhost", 5347); + xmpp = new StreamComponent(new JID("", "ws.juick.com", ""), socket.getInputStream(), socket.getOutputStream(), password); + xmpp.addChildParser(new JuickMessage()); + xmpp.addListener((Stream.StreamListener) this); + xmpp.addListener((Message.MessageListener) this); + xmpp.startParsing(); + } catch (IOException e) { + System.err.println(e); + } } @Override - public void onAuth(String resource) { - System.err.println("XMPP onAuth " + resource); + public void onStreamFail(String msg) { + System.err.println("Component stream failed: " + msg); } @Override - public void onAuthFailed(String message) { - System.err.println("XMPP onAuthFailed " + message); + public void onStreamReady() { + System.err.println("Component stream ready"); } public void setupWsServer() { @@ -115,10 +116,10 @@ public class Main implements XmppListener, MessageListener { while (true) { sel.select(); // System.out.println("ONE"); - Iterator it = sel.selectedKeys().iterator(); + Iterator it = sel.selectedKeys().iterator(); while (it.hasNext()) { // System.out.println("TWO"); - SelectionKey selKey = (SelectionKey) it.next(); + SelectionKey selKey = it.next(); it.remove(); if (selKey.isAcceptable()) { ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); -- cgit v1.2.3