Package org.xsocket.connection

Examples of org.xsocket.connection.INonBlockingConnection


  private static class TcpProxyHandler implements IDataHandler, IDisconnectHandler {
   
 
    public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
      INonBlockingConnection reverseConnection = (INonBlockingConnection) connection.getAttachment();
      if (reverseConnection != null) {
        connection.setAttachment(null);
        reverseConnection.close();
      }
      return true;
    }
View Full Code Here


      return true;
    }
   
   
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();
       
      int available = connection.available();
      if (available > 0) {
        ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
        forwardConnection.write(data);
      } else if (available == -1) {
        connection.close();
      }
     
      return true;
View Full Code Here

   
   
    private static class TcpProxyHandler implements IDataHandler, IDisconnectHandler {
       
        public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
            INonBlockingConnection reverseConnection = (INonBlockingConnection) connection.getAttachment();
            if (reverseConnection != null) {
                connection.setAttachment(null);
                NonBlockingConnectionPool.destroy(reverseConnection);
            }
            return true;
View Full Code Here

            return true;
        }
       
       
        public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
            INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();
               
            int available = connection.available();
            if (available > 0) {
                ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
                forwardConnection.write(data);
                forwardConnection.flush();
               
            } else if (available == -1) {
                NonBlockingConnectionPool.destroy(connection);
            }
           
View Full Code Here

        forwardHost = uri.substring(0, idx);
        forwardPort = Integer.parseInt(uri.substring(idx + 1, uri.length()));
      }
     
      try {
        INonBlockingConnection forwardCon = new NonBlockingConnection(forwardHost, forwardPort);
        INonBlockingConnection tcpCon = exchange.getConnection().getUnderlyingTcpConnection();

        forwardCon.setAttachment(tcpCon);
        tcpCon.setAttachment(forwardCon);
       
        forwardCon.setFlushmode(FlushMode.ASYNC);
        forwardCon.setAutoflush(true);
        tcpCon.setFlushmode(FlushMode.ASYNC);
        tcpCon.setAutoflush(true);

        forwardCon.setHandler(new TcpProxyHandler());
        tcpCon.setHandler(new TcpProxyHandler());
       
        IHttpResponse response = new HttpResponse(200);
        response.getResponseHeader().setReason("Connection established");
        response.setHeader("Proxy-agent", "myProxy");
        exchange.send(response);
View Full Code Here

  private static class TcpProxyHandler implements IDataHandler, IDisconnectHandler {
   
 
    public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
      INonBlockingConnection reverseConnection = (INonBlockingConnection) connection.getAttachment();
      if (reverseConnection != null) {
        connection.setAttachment(null);
        reverseConnection.close();
      }
      return true;
    }
View Full Code Here

      return true;
    }
   
   
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();
       
      int available = connection.available();
      if (available > 0) {
        ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
        forwardConnection.write(data);
        forwardConnection.flush();
      } else if (available == -1) {
        connection.close();
      }
     
      return true;
View Full Code Here

          host = target.substring(0, idx);
          port = Integer.parseInt(target.substring(idx + 1, target.length()).trim());
        }
       
       
        INonBlockingConnection tcpConnection = exchange.getConnection().getUnderlyingTcpConnection();
       
        SSLClientToProxyHandler proxyHandler = new SSLClientToProxyHandler(host, port, tcpConnection);
        tcpConnection.setHandler(proxyHandler);
       
        HttpResponse response = new HttpResponse(200);
        exchange.send(response);
      }
    }
View Full Code Here

  @Execution(Execution.NONTHREADED)
  private static class ProxyHandler implements IDataHandler, IDisconnectHandler {
   
 
    public boolean onDisconnect(INonBlockingConnection connection) throws IOException {
      INonBlockingConnection reverseConnection = (INonBlockingConnection) connection.getAttachment();
      if (reverseConnection != null) {
        connection.setAttachment(null);
        reverseConnection.close();
      }
      return true;
    }
View Full Code Here

      return true;
    }
   
   
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();

      ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
      forwardConnection.write(data);
     
      return true;
    }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.INonBlockingConnection

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.