Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.XMPPConnection


            ConnectionConfiguration("localhost", 61222);
        // config.setDebuggerEnabled(true);

        try {
            // SmackConfiguration.setPacketReplyTimeout(1000);
            XMPPConnection con = new XMPPConnection(config);
            con.connect();
            con.login("amq-user", "amq-pwd");
            ChatManager chatManager = con.getChatManager();
            Chat chat = chatManager.createChat("test@localhost", new MessageListener() {
                public void processMessage(Chat chat, Message message) {
                    System.out.println("Got XMPP message from chat " + chat.getParticipant() + " message - " + message.getBody());
                }
            });
            for (int i = 0; i < 10; i++) {
                System.out.println("Sending message: " + i);
                chat.sendMessage("Hello from Message: " + i);
            }
            System.out.println("Sent all messages!");
            con.disconnect();
        } catch (XMPPException e) {
            if (block) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
            } else {
View Full Code Here


    public void testChat() throws Exception {
        ConnectionConfiguration config = new ConnectionConfiguration("localhost", 61222);
        //config.setDebuggerEnabled(true);

        XMPPConnection consumerCon = new XMPPConnection(config);
        consumerCon.connect();
        consumerCon.login("consumer", "consumer");
        consumerCon.addPacketListener(new XmppLogger("CONSUMER INBOUND"), new PacketFilter() {
            public boolean accept(Packet packet) {
                return true;
            }
        });
        consumerCon.addPacketWriterListener(new XmppLogger("CONSUMER OUTBOUND"), new PacketFilter() {
            public boolean accept(Packet packet) {
                return true;
            }
        });
        final ConsumerMessageListener listener = new ConsumerMessageListener();

        consumerCon.getChatManager().addChatListener(new ChatManagerListener() {
            public void chatCreated(Chat chat, boolean createdLocally) {
                chat.addMessageListener(listener);
            }
        });


        XMPPConnection producerCon = new XMPPConnection(config);
        producerCon.connect();
        producerCon.login("producer", "producer");
        producerCon.addPacketListener(new XmppLogger("PRODUCER INBOUND"), new PacketFilter() {
            public boolean accept(Packet packet) {
                return true;
            }
        });
        producerCon.addPacketWriterListener(new XmppLogger("PRODUCER OUTBOUND"), new PacketFilter() {
            public boolean accept(Packet packet) {
                return true;
            }
        });

        Chat chat = producerCon.getChatManager().createChat("consumer", new MessageListener() {
            public void processMessage(Chat chat, Message message) {
                System.out.println("Got XMPP message from chat " + chat.getParticipant() + " message - " + message.getBody());
            }
        });
View Full Code Here

    public void testMultiUserChat() throws Exception {
        System.out.println("\n\n\n\n\n\n");
        ConnectionConfiguration config = new ConnectionConfiguration("localhost", 61222);
        //config.setDebuggerEnabled(true);
        //
        XMPPConnection consumerCon = new XMPPConnection(config);
        consumerCon.connect();
        consumerCon.login("consumer", "consumer");
        MultiUserChat consumerMuc = new MultiUserChat(consumerCon, "muc-test");
        consumerMuc.join("consumer");

        ConsumerMUCMessageListener listener = new ConsumerMUCMessageListener();
        consumerMuc.addMessageListener(listener);

        XMPPConnection producerCon = new XMPPConnection(config);
        producerCon.connect();
        producerCon.login("producer", "producer");
        MultiUserChat producerMuc = new MultiUserChat(producerCon, "muc-test");
        producerMuc.join("producer");

        for (int i = 0; i < 10; i++) {
            System.out.println("Sending message: " + i);
View Full Code Here

        System.out.println("\n\n\n\n\n\n");
        ConnectionConfiguration config = new ConnectionConfiguration("localhost", 61222);
        //config.setDebuggerEnabled(true);

        //create the consumer first...
        XMPPConnection consumerCon = new XMPPConnection(config);
        consumerCon.connect();
        addLoggingListeners("CONSUMER", consumerCon);
        consumerCon.login("consumer", "consumer");

        final ConsumerMessageListener listener1 = new ConsumerMessageListener();
        consumerCon.getChatManager().addChatListener(new ChatManagerListener() {
            public void chatCreated(Chat chat, boolean createdLocally) {
                chat.addMessageListener(listener1);
            }
        });
       
        //now create the producer
        XMPPConnection producerCon = new XMPPConnection(config);
        System.out.println("Connecting producer and consumer");
        producerCon.connect();
        addLoggingListeners("PRODUCER", producerCon);
        producerCon.login("producer", "producer");

        //create the chat and send some messages
        Chat chat = producerCon.getChatManager().createChat("consumer", new MessageListener() {
            public void processMessage(Chat chat, Message message) {
                System.out.println("Got XMPP message from chat " + chat.getParticipant() + " message - " + message.getBody());
            }
        });
       
        for (int i = 0; i < 10; i++) {
            System.out.println("Sending message: " + i);
            Message message = new Message("consumer");
            message.setType(Message.Type.chat);
            message.setBody("Hello from producer, message # " + i);
            chat.sendMessage(message);
        }
      
        //make sure the consumer has time to receive all the messages...
        Thread.sleep(sleepTime);

        //create an identical 2nd consumer
        XMPPConnection lastguyCon = new XMPPConnection(config);
        lastguyCon.connect();
        addLoggingListeners("LASTGUY", consumerCon);
        lastguyCon.login("consumer", "consumer");
        final ConsumerMessageListener listener2 = new ConsumerMessageListener();
        lastguyCon.getChatManager().addChatListener(new ChatManagerListener() {
            public void chatCreated(Chat chat, boolean createdLocally) {
                chat.addMessageListener(listener2);
            }
        });
View Full Code Here

        //config.setDebuggerEnabled(true);

        try {
            //SmackConfiguration.setPacketReplyTimeout(1000);
            //XMPPConnection con = new XMPPConnection(config);
            XMPPConnection con = new XMPPConnection("localhost", 61222);
            con.login("amq-user", "amq-pwd");
            Chat chat = con.createChat("test@localhost");
            for (int i = 0; i < 10; i++) {
                System.out.println("Sending message: " + i);
                chat.sendMessage("Hello from Message: " + i);
            }
            System.out.println("Sent all messages!");
View Full Code Here

                int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_SECURE_PORT;
                this.connection = new SSLXMPPConnection(xmppHost, port);
            }
            else {
                int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_PORT;
                this.connection = new XMPPConnection(xmppHost, port);
            }

            if (loginId != null) {
                // it is important to provide a (pseudo) globally unique string as the
                // third argument ("sessionHandle" is such string); without it same
View Full Code Here

        System.out.println();
       
        LinkedBlockingQueue<Packet> localClientPackages = new LinkedBlockingQueue<Packet>();
        LinkedBlockingQueue<Packet> remoteClientPackages = new LinkedBlockingQueue<Packet>();
       
        XMPPConnection localClient = connectClient(localConnect, localUser.getFullQualifiedName(), localPassword, keystorePath, keystorePassword, localClientPackages);
//        XMPPConnection localClient = null;

        System.out.println();
        System.out.println();
        System.out.println("Connecting remote client");
        System.out.println();
        System.out.println();

//        XMPPConnection remoteClient = connectClient(remoteServer, remoteUser, remotePassword, keystorePath, keystorePassword, remoteClientPackages);
        XMPPConnection remoteClient = null;

        Thread.sleep(3000);

        System.out.println();
        System.out.println();
        System.out.println("Sending message from local to remote");
        System.out.println();
        System.out.println();

        remoteClientPackages.clear();
        Message msg = new Message(remoteUser);
        msg.setBody("Hello world");
       
        localClient.sendPacket(msg);
       
//        Packet packet = remoteClientPackages.poll(15000, TimeUnit.MILLISECONDS);
//        if(packet != null && packet instanceof Message) {
//            System.out.println("!!!!!!" + ((Message)packet).getBody());
//        } else {
//            fail("Message not received by remote client");
//        }
//
//        Thread.sleep(3000);
//
//        System.out.println();
//        System.out.println();
//        System.out.println("Sending message from remote to local");
//        System.out.println();
//        System.out.println();
//
//        localClientPackages.clear();
//        msg = new Message(localUser.getFullQualifiedName());
//        msg.setBody("Hello world");
//       
//        remoteClient.sendPacket(msg);
//       
//        packet = localClientPackages.poll(15000, TimeUnit.MILLISECONDS);
//        if(packet != null && packet instanceof Message) {
//            System.out.println("!!!!!!" + ((Message)packet).getBody());
//        } else {
//            fail("Message not received by local client");
//        }
       
        Thread.sleep(15000);
        System.out.println();
        System.out.println();
        System.out.println("Closing down");
        System.out.println();
        System.out.println();

        remoteClient.disconnect();
        localClient.disconnect();
       
        Thread.sleep(5000);
       
        server.stop();
View Full Code Here

//        ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(host, 5222);
        ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(host, 5222, "protocol7.com");
        connectionConfiguration.setKeystorePath(keystorePath);
        connectionConfiguration.setTruststorePath(keystorePath);
        connectionConfiguration.setTruststorePassword(keystorePassword);
        XMPPConnection client = new XMPPConnection(connectionConfiguration);
       
        client.connect();
        client.login(user, password);
        client.addPacketListener(new PacketListener() {
            public void processPacket(Packet packet) {
                System.out.println("# " + packet);
                packageQueue.add(packet);
            }
        }, new PacketFilter() {
View Full Code Here

        connectionConfiguration.setKeystorePath("src/main/config/bogus_mina_tls.cert");
        connectionConfiguration.setTruststorePath("src/main/config/bogus_mina_tls.cert");
        connectionConfiguration.setTruststorePassword("boguspw");

        XMPPConnection.DEBUG_ENABLED = true;
        XMPPConnection client = new XMPPConnection(connectionConfiguration);

        client.connect();

        client.login(username, password);
        return client;
    }
View Full Code Here

   *
   * @return
   */
  public boolean testConnection() {
    boolean test = false;
    Connection conn = new XMPPConnection(server);
    try {
      conn.connect();
      conn.login(uid, pwd);
      conn.disconnect();
      test = true;
    } catch (XMPPException e) {
      logger.l2("XMPP connection test failed", e);
    }
    return test;
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.XMPPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.