Package org.xsocket.connection

Examples of org.xsocket.connection.NonBlockingConnection




  private static INonBlockingConnection newNonBlockingConnection(InetSocketAddress address) throws ConnectException {
    try {
      return new NonBlockingConnection(address);
    } catch (IOException ioe) {
      throw new ConnectException(ioe.toString());
    }
  }
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.getBody().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.getBody().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.getBody().readString());

       
        httpClient.close();
        nbc1.close();
        nbc2.close();
        nbc3.close();
        dualPortServer.close();
    }
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

    if (idx != -1) {
      forwardPort = Integer.parseInt(host.substring(idx + 1, host.length()));
      forwardHost = host.substring(0, idx);
    }

    INonBlockingConnection con = new NonBlockingConnection(securedProxyHost, securedProxyPort, sslContext, false);
    con.setHandler(new DataHandler(exchange));

   
    StringBuilder sb = new StringBuilder();
   
    sb.append("CONNECT " + forwardHost + ":" + forwardPort + " HTTP/1.1\r\n" +
          "Host: " + host + "\r\n" +
          "User-Agent: xLightweb/" + HttpUtils.getImplementationVersion() + "\r\n");
   
   
    if (proxyUser != null) {
      if (proxyUserPassword != null) {
        sb.append("Proxy-Authorization: Basic " + proxyUserPassword + "\r\n");
       
      } else {
        exchange.sendError(401, "proxy user password is not set (hint: usage <HttpClient>.setProxyPassword(...)");
        return;
      }
    }

    sb.append("Proxy-Connection: keep-alive\r\n" +
          "\r\n");
   
    con.write(sb.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

   
    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



  private static INonBlockingConnection newNonBlockingConnection(InetSocketAddress address) throws ConnectException {
    try {
      return new NonBlockingConnection(address);
    } 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

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.