Package java.nio.channels

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


     */
    public void test_socket_getLocalPort() throws IOException {
        serverChannel.socket().bind(localAddr1);
        clientChannel.connect(localAddr1);
        SocketChannel myChannel = serverChannel.accept();
        int port = myChannel.socket().getLocalPort();
        assertEquals(localAddr1.getPort(), port);
        myChannel.close();
        clientChannel.close();
        serverChannel.close();
    }
View Full Code Here


      SocketChannel channel;
      while ((channel = server.accept()) != null) {
        try {
          channel.configureBlocking(false);
          channel.socket().setTcpNoDelay(tcpNoDelay);
          channel.socket().setKeepAlive(tcpKeepAlive);
        } catch (IOException ioe) {
          channel.close();
          throw ioe;
        }
View Full Code Here

      SocketChannel channel;
      while ((channel = server.accept()) != null) {
        try {
          channel.configureBlocking(false);
          channel.socket().setTcpNoDelay(tcpNoDelay);
          channel.socket().setKeepAlive(tcpKeepAlive);
        } catch (IOException ioe) {
          channel.close();
          throw ioe;
        }
View Full Code Here

   public TcpTransport(InetSocketAddress serverAddress, TransportFactory transportFactory) {
      super(transportFactory);
      this.serverAddress = serverAddress;
      try {
         SocketChannel socketChannel = SocketChannel.open(serverAddress);
         socket = socketChannel.socket();
         socket.setTcpNoDelay(transportFactory.isTcpNoDelay());
      } catch (IOException e) {
         String message = "Could not connect to server: " + serverAddress;
         log.error(message, e);
         throw new TransportException(message, e);
View Full Code Here

    }

    private void tryToConnect(final InetSocketAddress socketAddress, final int timeout)
            throws Exception {
        final SocketChannel socketChannel = SocketChannel.open();
        connectionManager.initSocket(socketChannel.socket());
        if (connectionManager.ioService.isSocketBind()) {
            bindSocket(socketChannel);
        }
        final Level level = silent ? Level.FINEST : Level.INFO;
        if (logger.isLoggable(level)) {
View Full Code Here

        }
        try {
            socketChannel.configureBlocking(true);
            try {
                if (timeout > 0) {
                    socketChannel.socket().connect(socketAddress, timeout);
                } else {
                    socketChannel.connect(socketAddress);
                }
            } catch (SocketException ex) {
                //we want to include the socketAddress in the exception.
View Full Code Here

                SocketException newEx = new SocketException(ex.getMessage() + " to address " + socketAddress);
                newEx.setStackTrace(ex.getStackTrace());
                throw newEx;
            }
            if (logger.isFinestEnabled()) {
                log(Level.FINEST, "Successfully connected to: " + address + " using socket " + socketChannel.socket());
            }
            final SocketChannelWrapper socketChannelWrapper = connectionManager.wrapSocketChannel(socketChannel, true);
            MemberSocketInterceptor memberSocketInterceptor = connectionManager.getMemberSocketInterceptor();
            if (memberSocketInterceptor != null) {
                if (logger.isFinestEnabled()) {
View Full Code Here

            MemberSocketInterceptor memberSocketInterceptor = connectionManager.getMemberSocketInterceptor();
            if (memberSocketInterceptor != null) {
                if (logger.isFinestEnabled()) {
                    log(Level.FINEST, "Calling member socket interceptor: " + memberSocketInterceptor + " for " + socketChannel);
                }
                memberSocketInterceptor.onConnect(socketChannel.socket());
            }

            socketChannelWrapper.configureBlocking(false);
            TcpIpConnection connection = connectionManager.assignSocketChannel(socketChannelWrapper);
            connection.getWriteHandler().setProtocol(Protocols.CLUSTER);
View Full Code Here

                throw new HazelcastException("ConnectionManager is not active!!!");
            }
            SocketChannel socketChannel = null;
            try {
                socketChannel = SocketChannel.open();
                Socket socket = socketChannel.socket();
                socket.setKeepAlive(socketOptions.isKeepAlive());
                socket.setTcpNoDelay(socketOptions.isTcpNoDelay());
                socket.setReuseAddress(socketOptions.isReuseAddress());
                if (socketOptions.getLingerSeconds() > 0) {
                    socket.setSoLinger(true, socketOptions.getLingerSeconds());
View Full Code Here

                if (bufferSize < 0) {
                    bufferSize = BUFFER_SIZE;
                }
                socket.setSendBufferSize(bufferSize);
                socket.setReceiveBufferSize(bufferSize);
                socketChannel.socket().connect(address.getInetSocketAddress(), 5000);
                SocketChannelWrapper socketChannelWrapper = socketChannelWrapperFactory.wrapSocketChannel(socketChannel, true);
                final ClientConnection clientConnection = new ClientConnection(ClientConnectionManagerImpl.this, inSelector,
                        outSelector, connectionIdGen.incrementAndGet(), socketChannelWrapper, executionService);
                socketChannel.configureBlocking(true);
                if (socketInterceptor != null) {
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.