aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick/jabber/ws/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/juick/jabber/ws/Main.java')
-rw-r--r--src/com/juick/jabber/ws/Main.java43
1 files 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<SocketSubscribed> sockReplies = new ArrayList<SocketSubscribed>();
ArrayList<SocketSubscribed> sockMessages = new ArrayList<SocketSubscribed>();
ArrayList<SocketSubscribed> sockAll = new ArrayList<SocketSubscribed>();
@@ -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<SelectionKey> 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();