Package java.nio.channels

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


                while (!Thread.interrupted()) {
                    SocketChannel sc = ssc.accept();
                    if (BUSY)
                        sc.configureBlocking(false);

                    String ra = sc.socket().getInetAddress().toString();
                    System.err.println("... connect to " + ra);
                    try {
                        sc.socket().setTcpNoDelay(true);
                        while (sc.read(bb) >= 0) {
                            bb.flip();
View Full Code Here


                        sc.configureBlocking(false);

                    String ra = sc.socket().getInetAddress().toString();
                    System.err.println("... connect to " + ra);
                    try {
                        sc.socket().setTcpNoDelay(true);
                        while (sc.read(bb) >= 0) {
                            bb.flip();
//                            System.out.println("e "+bb.remaining());
                            IOTools.writeAllOrEOF(sc, bb);
                            bb.clear();
View Full Code Here

        if (state == Connection.OPEN) // open attempt graceful
        // shutdown
        {
          log.fine("shutting down");
          state = Connection.CLOSING;
          Socket sock = sc.socket();
          try {
            sock.shutdownOutput();
          } catch (IOException se) {
            log.severe("shutdown failed: " + se.getMessage());
            log.log(Level.FINE, "details: ", se);
View Full Code Here

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

      for (int i=0; i<10; i++) {
        SocketChannel channel = server.accept();
        if (channel==null) return;

        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

    {
        SocketChannel channel = SocketChannel.open();
        Address address = destination.isProxied() ? destination.getProxy() : destination.getAddress();
        channel.connect(address.toSocketAddress());
        channel.configureBlocking( false );
        channel.socket().setSoTimeout( _httpClient.getSoTimeout());
        _selectorManager.register( channel, destination );
    }

    public void run()
    {
View Full Code Here

  @Override
  public ServerContext createContext(TProtocol input, TProtocol output, Object selectionKeyObject) {
    LOG.debug("Client connected");
    SelectionKey selectionKey = (SelectionKey) selectionKeyObject;
    SocketChannel channel = (SocketChannel) selectionKey.channel();
    Socket socket = channel.socket();
    SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
    SocketAddress localSocketAddress = socket.getLocalSocketAddress();
    _connectionMeter.mark();
    _connections.incrementAndGet();
    return new ControllerServerContext(localSocketAddress, remoteSocketAddress);
View Full Code Here

  @Override
  public ServerContext createContext(TProtocol input, TProtocol output, Object selectionKeyObject) {
    LOG.debug("Client connected");
    SelectionKey selectionKey = (SelectionKey) selectionKeyObject;
    SocketChannel channel = (SocketChannel) selectionKey.channel();
    Socket socket = channel.socket();
    SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
    SocketAddress localSocketAddress = socket.getLocalSocketAddress();
    _connectionMeter.mark();
    _connections.incrementAndGet();
    return new ShardServerContext(localSocketAddress, remoteSocketAddress);
View Full Code Here

      ServerSocketChannel server = (ServerSocketChannel) key.channel();

      SocketChannel channel;
      while ((channel = server.accept()) != null) {
        channel.configureBlocking(false);
        channel.socket().setTcpNoDelay(tcpNoDelay);
        channel.socket().setKeepAlive(tcpKeepAlive);

        Reader reader = getReader();
        try {
          reader.startAdd();
View Full Code Here

      SocketChannel channel;
      while ((channel = server.accept()) != null) {
        channel.configureBlocking(false);
        channel.socket().setTcpNoDelay(tcpNoDelay);
        channel.socket().setKeepAlive(tcpKeepAlive);

        Reader reader = getReader();
        try {
          reader.startAdd();
          SelectionKey readKey = reader.registerChannel(channel);
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.