Package org.xsocket.connection

Examples of org.xsocket.connection.NonBlockingConnection


   
    public SSLClientToProxyHandler(String forwardHost, int forwardPort, INonBlockingConnection clientToProxyConnection) throws IOException {
      clientToProxyConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      clientToProxyConnection.setAutoflush(true);
     
      INonBlockingConnection proxyToServerConnection = new NonBlockingConnection(InetAddress.getByName(forwardHost), forwardPort, new ProxyHandler(), 60 * 1000, SSLTestContextFactory.getSSLContext(), true, clientToProxyConnection.getWorkerpool());
     
      proxyToServerConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      proxyToServerConnection.setAutoflush(true);
      proxyToServerConnection.setAttachment(clientToProxyConnection);
     
      clientToProxyConnection.setAttachment(proxyToServerConnection);
    }
View Full Code Here


 
  @Test
  public void testLifeAsyncConnect() throws Exception {
     
      ConnectHandler ch = new ConnectHandler();
      new NonBlockingConnection(InetAddress.getByName("www.gmx.com"), 80, ch, false, 2000);
     
      QAUtil.sleep(1500);
     
      IHttpClientEndpoint httpEndpoint = ch.getHttpConnection();
      IHttpResponse response = httpEndpoint.call(new GetRequest("/"));
View Full Code Here

  public void testAsyncConnectFailed() throws Exception {
         
    int connectionTimeoutMillis = 1000;
   
      ConnectHandler ch = new ConnectHandler();
      new NonBlockingConnection(InetAddress.getByName("192.168.255.255"), 80, ch, false, connectionTimeoutMillis);
         
      QAUtil.sleep(3000);
     
      if (ch.getIOException() == null) {
        System.out.println("exception expected");
View Full Code Here

        SimpleDualPortServer dualPortServer = new SimpleDualPortServer(0, 0);
        new Thread(dualPortServer).start();
       
        QAUtil.sleep(1000);
    
        INonBlockingConnection nbc1 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc1.write((int) 55);
       
        INonBlockingConnection nbc2 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc2.write((int) 55);
       
        INonBlockingConnection nbc3 = new NonBlockingConnection("localhost", dualPortServer.getTcpServerListenPort(), new EchoDataHandler());
        nbc3.write((int) 66);
       
        QAUtil.sleep(1000);
       
        HttpClient httpClient = new HttpClient();

        IHttpResponse response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you", response.getBlockingBody().readString());
       

        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/66", "text/plain", "hello you2"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you2", response.getBlockingBody().readString());


        response = httpClient.call(new PostRequest("http://localhost:" + dualPortServer.getHttpServerListenPort() + "/55", "text/plain", "hello you3"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("hello you3", response.getBlockingBody().readString());

       
        httpClient.close();
        nbc1.close();
        nbc2.close();
        nbc3.close();
        dualPortServer.close();
    }
View Full Code Here


  private static INonBlockingConnection newNonBlockingConnection(InetSocketAddress address, Executor workerpool) throws ConnectException {
    try {
        if (workerpool == null) {
            return new NonBlockingConnection(address);
        } else {
            return new NonBlockingConnection(address.getHostName(), address.getPort(), null, workerpool);
        }
    } catch (IOException ioe) {
      throw new ConnectException(ioe.toString());
    }
  }
View Full Code Here

 
  @Test
  public void testLifeAsyncConnect() throws Exception {
      
      ConnectHandler ch = new ConnectHandler();
      new NonBlockingConnection(InetAddress.getByName("www.web.de"), 80, ch, false, 2000);
     
      QAUtil.sleep(1500);
     
      IHttpClientEndpoint httpEndpoint = ch.getHttpConnection();
      IHttpResponse response = httpEndpoint.call(new GetRequest("/"));
View Full Code Here

  public void testAsyncConnectFailed() throws Exception {
         
    int connectionTimeoutMillis = 1000;
   
      ConnectHandler ch = new ConnectHandler();
      new NonBlockingConnection(InetAddress.getByName("192.168.255.255"), 80, ch, false, connectionTimeoutMillis);
         
      QAUtil.sleep(3000);
     
      if (ch.getIOException() == null) {
        System.out.println("exception expected");
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");
View Full Code Here

     * @param targetHost       the target host
     * @param targetPort       the target port
     * @throws IOException if an exception occurs
     */
    public static void establishTcpTunnel(IHttpConnection httpConnection, String targetHost, int targetPort) throws IOException {
        INonBlockingConnection forwardCon = new NonBlockingConnection(targetHost, targetPort);
       
        INonBlockingConnection tcpCon = httpConnection.getUnderlyingTcpConnection();

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

        forwardCon.setHandler(new TcpProxyHandler());
        tcpCon.setHandler(new TcpProxyHandler());
    }
View Full Code Here

   
    public SSLClientToProxyHandler(String forwardHost, int forwardPort, INonBlockingConnection clientToProxyConnection) throws IOException {
      clientToProxyConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      clientToProxyConnection.setAutoflush(true);
     
      INonBlockingConnection proxyToServerConnection = new NonBlockingConnection(InetAddress.getByName(forwardHost), forwardPort, new ProxyHandler(), 60 * 1000, SSLTestContextFactory.getSSLContext(), true, clientToProxyConnection.getWorkerpool());
     
      proxyToServerConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      proxyToServerConnection.setAutoflush(true);
      proxyToServerConnection.setAttachment(clientToProxyConnection);
     
      clientToProxyConnection.setAttachment(proxyToServerConnection);
    }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.NonBlockingConnection

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.