Examples of SocketChannel


Examples of java.nio.channels.SocketChannel

        }
      }
     
      while( !pending_closes.isEmpty() ) {
       
        SocketChannel channel = pending_closes.removeFirst();
       
        if( channel != null ) {
         
          connect_selector.cancel( channel );
         
          try{
            channel.close();
           
          }catch( Throwable t ){
           
            /*Debug.printStackTrace(t);*/
          }
View Full Code Here

Examples of java.nio.channels.SocketChannel

        }

        public void run() {
            try {
                while (true) {
                    SocketChannel socket = serverSocket.accept();
                    InetSocketAddress remoteAddress = (InetSocketAddress) socket.socket().getRemoteSocketAddress();
                    if (!localAddresses.contains(remoteAddress.getAddress())) {
                        LOGGER.error("Cannot accept connection from remote address {}.", remoteAddress.getAddress());
                    }
                    URI remoteUri = new URI(String.format("tcp://localhost:%d", remoteAddress.getPort()));
                    LOGGER.debug("Accepted connection from {}.", remoteUri);
View Full Code Here

Examples of java.nio.channels.SocketChannel

    public void run() {
        final ExecutorService execPool = this.execPool;
        final TransferRequestListener handler = this.handler;
        try {
            while(true) {
                SocketChannel channel = serverChannel.accept();
                execPool.execute(new RequestHandler(channel, handler));
            }
        } catch (ClosedByInterruptException interrupted) {
            if(LOG.isDebugEnabled()) {
                LOG.debug("Avoidable interrupt happened (Normal case): " + interrupted.getMessage());
View Full Code Here

Examples of java.nio.channels.SocketChannel

        // Now try each address
        try {
            SocketException lastFailure = null;
            for (InetAddress address : loopBackAddresses) {
                LOGGER.debug("Trying to connect to address {}.", address);
                SocketChannel socketChannel;
                try {
                    socketChannel = SocketChannel.open(new InetSocketAddress(address, destinationUri.getPort()));
                } catch (SocketException e) {
                    LOGGER.debug("Cannot connect to address {}, skipping.", address);
                    lastFailure = e;
                    continue;
                }
                LOGGER.debug("Connected to address {}.", address);
                URI localAddress = new URI(String.format("tcp://localhost:%d", socketChannel.socket().getLocalPort()));
                return new SocketConnection<T>(socketChannel, localAddress, destinationUri, classLoader);
            }
            throw lastFailure;
        } catch (java.net.ConnectException e) {
            throw new ConnectException(String.format("Could not connect to server %s. Tried addresses: %s.",
View Full Code Here

Examples of java.nio.channels.SocketChannel

        if(!file.canRead()) {
            throw new IllegalArgumentException(file.getAbsolutePath() + " cannot read");
        }

        final SocketAddress dstSockAddr = new InetSocketAddress(dstAddr, dstPort);
        SocketChannel channel = null;
        Socket socket = null;
        final OutputStream out;
        try {
            channel = SocketChannel.open();
            socket = channel.socket();
            socket.connect(dstSockAddr);
            out = socket.getOutputStream();
        } catch (IOException e) {
            LOG.error("failed to connect: " + dstSockAddr, e);
            IOUtils.closeQuietly(channel);
View Full Code Here

Examples of java.nio.channels.SocketChannel

    }

    public static void send(@Nonnull final FastByteArrayOutputStream data, @Nonnull final String fileName, @Nullable final String writeDirPath, @Nonnull final InetAddress dstAddr, final int dstPort, final boolean append, final boolean sync, @Nullable final TransferClientHandler handler)
            throws IOException {
        final SocketAddress dstSockAddr = new InetSocketAddress(dstAddr, dstPort);
        SocketChannel channel = null;
        Socket socket = null;
        final OutputStream out;
        try {
            channel = SocketChannel.open();
            socket = channel.socket();
            socket.connect(dstSockAddr);
            out = socket.getOutputStream();
        } catch (IOException e) {
            LOG.error("failed to connect: " + dstSockAddr, e);
            IOUtils.closeQuietly(channel);
View Full Code Here

Examples of java.nio.channels.SocketChannel

    long  failed_accepts    = 0;

    while(true){
     
      try{       
        SocketChannel socket_channel = ssc.accept();
           
        successfull_accepts++;
       
        if ( !( allow_external_access || socket_channel.socket().getInetAddress().isLoopbackAddress())){
         
          if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING,
                "AEProxy: incoming connection from '"
                    + socket_channel.socket().getInetAddress()
                    + "' - closed as not local"));
       
          socket_channel.close();
         
        }else{
           
          socket_channel.configureBlocking(false);
 
          AEProxyConnectionImpl processor = new AEProxyConnectionImpl(this, socket_channel, proxy_handler);
         
          if ( !processor.isClosed()){
           
View Full Code Here

Examples of java.nio.channels.SocketChannel

  void connect() {
    connecting_thread = new JMThread() {
      public void run() {     
        try {
          connection_status = ConnectionStatus.CONNECTING;
          SocketChannel channel = SocketChannel.open();
         
          jm_socket_channel = new JMuleSocketChannel(channel);
         
          jm_socket_channel.connect(remote_inet_socket_address, ConfigurationManager.SERVER_CONNECTING_TIMEOUT);
         
View Full Code Here

Examples of java.nio.channels.SocketChannel

        Iterator i = selectedKeys.iterator();
        while (i.hasNext()) {
            SelectionKey key = (SelectionKey) i.next();
            if (key.isAcceptable()) {
                ServerSocketChannel ssc = (ServerSocketChannel) key.channel();
                SocketChannel sc = ssc.accept();
                sc.configureBlocking(false);
                sc.register(this.selector, SelectionKey.OP_READ);
            } else if (key.isReadable()) {
                SocketChannel sc = (SocketChannel) key.channel();
                ByteBuffer buffer = ByteBuffer.allocate(10);
                buffer.clear();
                sc.read(buffer);
                buffer.flip();
                sc.write(buffer);
                sc.close();
            }
            i.remove();
        }
    }
View Full Code Here

Examples of java.nio.channels.SocketChannel

    // For an accept to be pending the channel must be a server socket
    // channel.
    ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();

    // Accept the connection and make it non-blocking
    SocketChannel socketChannel = serverSocketChannel.accept();
    socketChannel.configureBlocking(false);

    // Register the new SocketChannel with our Selector, indicating
    // we'd like to be notified when there's data waiting to be read
    socketChannel.register(this.selector, SelectionKey.OP_READ);

    worker.onConnect(socketChannel);
  }
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.