Package java.nio.channels

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


                    }
                }
                if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT)
                {
                    SocketChannel ch = (SocketChannel)key.channel();
                    java.net.Socket ss = (java.net.Socket)ch.socket();
                    Socket s = (Socket)key.attachment();
                    if (s != null)
                    {
//                        System.out.println(s + ": OnConnect");
                        ch.finishConnect();
View Full Code Here


            if(localHost == null) {
                InetSocketAddress addr = new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort);
                channel = SocketChannel.open(addr);
            } else {
                channel = SocketChannel.open();
                Socket socket = channel.socket();
                socket.bind(new InetSocketAddress(InetAddress.getByName(localHost), localPort));
                socket.connect(new InetSocketAddress(InetAddress.getByName(remoteHost), remotePort));
            }
            channel.finishConnect();
            initSocket(context.getRuntime(), new ChannelDescriptor(channel, RubyIO.getNewFileno(), new ModeFlags(ModeFlags.RDWR), new FileDescriptor()));
View Full Code Here

        return socketChannel;
    }
   
    private void dispatchTranslatedData(IRandomAccessDataBuffer randomAccessDataBuffer, int dataId) throws IOException{
        SocketChannel socketChannel =  openDataTransferChane();
        Socket socket = socketChannel.socket();
        try {
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            dos.writeInt(dataId);
            long len = randomAccessDataBuffer.length();
            if(randomAccessDataBuffer.transferTo(0, len , socketChannel)!=len){
View Full Code Here

        } catch (IOException e) {
            throw new MinaRuntimeException("can't create a new socket, out of file descriptors ?", e);
        }

        try {
            clientSocket.socket().setSoTimeout(getConnectTimeoutMillis());
        } catch (SocketException e) {
            throw new MinaRuntimeException("can't set socket timeout", e);
        }

        // non blocking
View Full Code Here

        if (receiveBufferSize != null) {
            session.getConfig().setReadBufferSize(receiveBufferSize);
        } else {
            int rcvBufferSize;
            try {
                rcvBufferSize = clientSocket.socket().getReceiveBufferSize();
            } catch (SocketException e) {
                throw new MinaRuntimeException("can't configure socket receive buffer size", e);
            }
            session.getConfig().setReadBufferSize(rcvBufferSize);
        }
View Full Code Here

        if (sendBufferSize != null) {
            session.getConfig().setSendBufferSize(sendBufferSize);
        } else {
            int sndBufferSize;
            try {
                sndBufferSize = clientSocket.socket().getSendBufferSize();
            } catch (SocketException e) {
                throw new MinaRuntimeException("can't configure socket send buffe size", e);
            }
            session.getConfig().setSendBufferSize(sndBufferSize);
        }
View Full Code Here

            buffer.clear();    // make buffer empty
        }
        //check to see if any data is available
        int pkgcnt = reader.execute();
        if (log.isTraceEnabled()) {
            log.trace("sending " + pkgcnt + " ack packages to " + channel.socket().getLocalPort() );
        }
       
        if (sendAck) {
            while ( pkgcnt > 0 ) {
                sendAck(key,channel);
View Full Code Here

    void doAccept(SelectionKey key) throws IOException,  OutOfMemoryError {
      Connection c = null;
      ServerSocketChannel server = (ServerSocketChannel) key.channel();
      SocketChannel channel = server.accept();
      channel.configureBlocking(false);
      channel.socket().setTcpNoDelay(tcpNoDelay);
      SelectionKey readKey = channel.register(selector, SelectionKey.OP_READ);
      c = new Connection(readKey, channel, System.currentTimeMillis());
      readKey.attach(c);
      synchronized (connectionList) {
        connectionList.add(numConnections, c);
View Full Code Here

                // If serverSocketChannel is blocking, this method blocks.
                // The returned channel is in blocking mode.
                final SocketChannel socketChannel = serverSocketChannel.accept();

                // deactivate Nagle algorithm
                socketChannel.socket().setTcpNoDelay(true);

                connection = new TargetConnection(socketChannel, true);
                try {
                    final ProtocolDataUnit pdu = connection.receivePdu();
                    // confirm OpCode-
View Full Code Here

            try {
                readBuffer.clear();
                readBuffer.limit(0);

                SocketChannel sc = SocketChannel.open(address);
                sc.socket().setReceiveBufferSize(256 * 1024);
                logger.info("Connected to " + address);
                ByteBuffer bb = ByteBuffer.allocate(8);
                bb.putLong(0, chronicle.size());
                IOTools.writeAllOrEOF(sc, bb);
                return sc;
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.