Package java.nio.channels

Examples of java.nio.channels.SocketChannel.finishConnect()


                SessionRequestHandle requestHandle = (SessionRequestHandle) key.attachment();
                SessionRequestImpl sessionRequest = requestHandle.getSessionRequest();
               
                // Finish connection process
                try {
                    channel.finishConnect();
                } catch (IOException ex) {
                    sessionRequest.failed(ex);
                }
                key.cancel();
                if (channel.isConnected()) {
View Full Code Here


        socketChannel.configureBlocking(true);
        socketChannel.connect(new InetSocketAddress("google.com", 443));

        // Complete connection
//        int i = 0;
        while (!socketChannel.finishConnect()) {
//            System.out.println("----------" + i++);
            Thread.sleep(50);
            // do something until connect completed
        }
View Full Code Here

                while (it.hasNext()) {
                    SelectionKey key = it.next();
                    if (key.isConnectable()) {
                        SocketChannel ch = (SocketChannel) key.channel();
                        if (ch.finishConnect()) {
                            ++connected;
                            if (connected % (connectionPerIP * locals.length / 10) == 0) {
                                System.out.println("connected: " + connected);
                            }
                            key.interestOps(SelectionKey.OP_READ);
View Full Code Here

            while (it.hasNext()) {
                SelectionKey key = it.next();
                SocketChannel ch = (SocketChannel) key.channel();
                if (key.isConnectable()) {
                    try {
                        if (ch.finishConnect()) {
                            ++connected;
                            key.interestOps(SelectionKey.OP_WRITE);
                        }
                    } catch (Exception e) {
                        ch.close();
View Full Code Here

                while (it.hasNext()) {
                    SelectionKey key = it.next();
                    if (key.isConnectable()) {
                        SocketChannel ch = (SocketChannel) key.channel();
                        try {
                            if (ch.finishConnect()) {
                                key.interestOps(SelectionKey.OP_WRITE);
                            }
                        } catch (Exception e) {
                            ch.close();
                            e.printStackTrace();
View Full Code Here

    }

    private static void finishConnect(SelectionKey key) {
        SocketChannel ch = (SocketChannel) key.channel();
        try {
            if (ch.finishConnect()) {
                ++connected;
                key.interestOps(SelectionKey.OP_WRITE);
            }
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

    private void finishConnect(SelectionKey key, long now) {
        SocketChannel ch = (SocketChannel) key.channel();
        Request req = (Request) key.attachment();
        try {
            if (ch.finishConnect()) {
                req.isConnected = true;
                req.onProgress(now);
                key.interestOps(OP_WRITE);
                if (req instanceof HttpsRequest) {
                    ((HttpsRequest) req).engine.beginHandshake();
View Full Code Here

                SocketChannel socket = (SocketChannel)channel;
                boolean result;
               
                if (socket.isConnectionPending()) {
                    // connection initiated but not finished
                    result = socket.finishConnect();
                } else {
                    result = socket.connect(addr);
                }

                if(!result) {
View Full Code Here

                } else {
                    SocketChannel connected = ssc.accept();
                    if (connected == null) continue;

                    connected.finishConnect();

                    // Force the client socket to be blocking
                    synchronized (connected.blockingLock()) {
                        connected.configureBlocking(false);
                        connected.configureBlocking(true);
View Full Code Here

            try {
                // Do this nonblocking so we can be interrupted
                channel.configureBlocking(false);
                channel.connect( new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort) );
                context.getThread().select(channel, this, SelectionKey.OP_CONNECT);
                channel.finishConnect();

                // only try to set blocking back if we succeeded to finish connecting
                channel.configureBlocking(true);

                initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR)));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.