Package java.nio.channels

Examples of java.nio.channels.SocketChannel


      throws IOException
    {
        // socket SX -> SY via BX
        // so if SX = source_channel then BX is target buffer
     
      SocketChannel  chan1 = sc;
      SocketChannel  chan2 = sc==source_channel?target_channel:source_channel;
     
      DirectByteBuffer  read_buffer = sc==source_channel?target_buffer:source_buffer;
     
      int written = read_buffer.write( DirectByteBuffer.SS_PROXY, chan1 );
           
View Full Code Here


 
  protected void
  outgoing()
  {
    try{     
      final SocketChannel  channel = SocketChannel.open();
     
      channel.configureBlocking( false );
   
      if ( channel.connect( new InetSocketAddress("localhost", 8765 ))){
             
        outgoing( channel );
       
      }else{
       
        connect_selector.register(
          channel,
          new VirtualSelectorListener()
          {
            public boolean
            selectSuccess(
              VirtualChannelSelector selector, SocketChannel sc, Object attachment)
            {
              try{
                if ( channel.finishConnect()){
                 
                  outgoing( channel );
                 
                  return( true );
                }else{
View Full Code Here

 
  private final TransportEndpoint      transport_endpoint;
  private final TransportHelperFilter   filter; 
 
  public LightweightTCPTransport( ProtocolEndpoint  pe, TransportHelperFilter filter ) {
    SocketChannel channel = ((TCPTransportHelper)filter.getHelper()).getSocketChannel();
    transport_endpoint  = new TransportEndpointTCP( pe, channel );
    this.filter = filter;
  }
View Full Code Here

  int            local_port,
  TransportHelperFilter   filter )

  {
    SocketChannel  channel = ((TCPTransportHelper)filter.getHelper()).getSocketChannel();
      
    //set advanced socket options
    try {
      int so_sndbuf_size = COConfigurationManager.getIntParameter( "network.tcp.socket.SO_SNDBUF" );
      if( so_sndbuf_size > 0 channel.socket().setSendBufferSize( so_sndbuf_size );
     
      String ip_tos = COConfigurationManager.getStringParameter( "network.tcp.socket.IPDiffServ" );
      if( ip_tos.length() > 0 channel.socket().setTrafficClass( Integer.decode( ip_tos ).intValue() );
    }
    catch( Throwable t ) {
      t.printStackTrace();
    }
   
  InetSocketAddress tcp_address = new InetSocketAddress( channel.socket().getInetAddress(), channel.socket().getPort());

  ConnectionEndpoint  co_ep = new ConnectionEndpoint(tcp_address);

  ProtocolEndpointTCP  pe_tcp = (ProtocolEndpointTCP)ProtocolEndpointFactory.createEndpoint( ProtocolEndpoint.PROTOCOL_TCP, co_ep, tcp_address );
View Full Code Here

        }
      }, null );
    }
    catch( Throwable t ) {
      Debug.out( t );
      SocketChannel chan = proxy_connection.getSocketChannel();
      if ( chan != null ){
        TCPNetworkManager.getSingleton().getReadSelector().cancel( chan );
      }
      proxy_listener.connectFailure( t );
    }
View Full Code Here

      Debug.out( "socket_channel == null" );
      return;
    }
   
    try{
      SocketChannel  channel = getSocketChannel();
     
      channel.socket().setSendBufferSize( size_in_bytes );
      channel.socket().setReceiveBufferSize( size_in_bytes );
     
      int snd_real = channel.socket().getSendBufferSize();
      int rcv_real = channel.socket().getReceiveBufferSize();
     
      if (Logger.isEnabled())
        Logger.log(new LogEvent(LOGID, "Setting new transport [" + description
          + "] buffer sizes: SND=" + size_in_bytes + " [" + snd_real
          + "] , RCV=" + size_in_bytes + " [" + rcv_real + "]"));
View Full Code Here

       
        if( waiting_time > request.connect_timeout ) {
         
          i.remove();
 
          SocketChannel channel = request.channel;
         
          connect_selector.cancel( channel );
 
          closeConnection( channel );
View Full Code Here

        }
      }
     
      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

        }

        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

    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

TOP

Related Classes of java.nio.channels.SocketChannel

Copyright © 2018 www.massapicom. 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.