Package rocks.xmpp.extensions.bytestreams

Examples of rocks.xmpp.extensions.bytestreams.ByteStreamSession


            public void run() {
                InBandByteStreamManager inBandBytestreamManager2 = xmppSession2.getExtensionManager(InBandByteStreamManager.class);
                inBandBytestreamManager2.addByteStreamListener(new ByteStreamListener() {
                    @Override
                    public void byteStreamRequested(final ByteStreamEvent e) {
                        final ByteStreamSession ibbSession;

                        try {
                            ibbSession = e.accept();

                            new Thread() {
                                @Override
                                public void run() {

                                    InputStream inputStream;
                                    try {
                                        inputStream = ibbSession.getInputStream();

                                        int b;
                                        while ((b = inputStream.read()) > -1) {
                                            outputStream.write(b);
                                        }
                                        outputStream.flush();
                                        outputStream.close();
                                        inputStream.close();

                                    } catch (IOException e1) {
                                        e1.printStackTrace();
                                    } finally {
                                        try {
                                            lock.lock();
                                            condition.signal();
                                        } finally {
                                            lock.unlock();
                                        }
                                    }
                                }
                            }.start();
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                    }
                });

                InBandByteStreamManager inBandBytestreamManager1 = xmppSession1.getExtensionManager(InBandByteStreamManager.class);
                ByteStreamSession ibbSession;
                try {
                    ibbSession = inBandBytestreamManager1.initiateSession(JULIET, "sid", 4096);
                    OutputStream os = ibbSession.getOutputStream();
                    os.write(new byte[]{1, 2, 3, 4});
                    os.flush();
                    os.close();
                } catch (IOException | XmppException e) {
                    e.printStackTrace();
View Full Code Here


        FeatureNegotiation featureNegotiation = streamInitiation.getFeatureNegotiation();
        // Get the stream method which has been chosen by the recipient.
        String streamMethod = featureNegotiation.getDataForm().findField(STREAM_METHOD).getValues().get(0);

        ByteStreamSession byteStreamSession;
        // Choose the stream method to be used based on the recipient's choice.
        switch (streamMethod) {
            case Socks5ByteStream.NAMESPACE:
                try {
                    byteStreamSession = socks5ByteStreamManager.initiateSession(receiver, sessionId);
                } catch (Exception e) {
                    // As fallback, if SOCKS5 negotiation failed, try IBB.
                    byteStreamSession = inBandByteStreamManager.initiateSession(receiver, sessionId, 4096);
                }
                break;
            case InBandByteStream.NAMESPACE:
                byteStreamSession = inBandByteStreamManager.initiateSession(receiver, sessionId, 4096);
                break;
            default:
                throw new IOException("Receiver returned unsupported stream method.");
        }
        return byteStreamSession.getOutputStream();
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.extensions.bytestreams.ByteStreamSession

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.