Examples of Tcp2Listener


Examples of etch.util.core.nio.Tcp2Listener

  @Test
  public void start1() throws Exception
  {
    MyListenerHandler lh = new MyListenerHandler();
   
    Tcp2Listener l = new Tcp2Listener( "tcp://0.0.0.0:0", r );
    l.setSession( lh );
   
    assertWhat( null, lh.what );
    assertNull( lh.xsocket );

    l.start();
    l.waitUp( TIMEOUT );

    assertTrue( l.isStarted() );

    assertWhat( What.UP, lh.what );
    assertNull( lh.xsocket );

    InetSocketAddress a = (InetSocketAddress) l.localAddress();
    if ( a.getAddress() instanceof Inet6Address )
      assertEquals( "0:0:0:0:0:0:0:0", a.getAddress().getHostAddress().toString() );
    else
      assertEquals( "0.0.0.0", a.getAddress().getHostAddress().toString() );
    assertTrue( a.getPort() > 0 && a.getPort() < 65536 );

    l.stop();
    l.waitDown( TIMEOUT );

    assertFalse( l.isStarted() );

    assertWhat( What.DOWN, lh.what );
    assertNull( lh.xsocket );
  }
View Full Code Here

Examples of etch.util.core.nio.Tcp2Listener

  /** @throws Exception */
  @Test
  public void start2() throws Exception
  {
    MyListenerHandler lh = new MyListenerHandler();
    Tcp2Listener l = new Tcp2Listener( "tcp://127.0.0.1:0", r );
    l.setSession( lh );
   
    assertWhat( null, lh.what );
    assertNull( lh.xsocket );

    l.start();
    l.waitUp( TIMEOUT );

    assertTrue( l.isStarted() );

    assertWhat( What.UP, lh.what );
    assertNull( lh.xsocket );

    InetSocketAddress a = (InetSocketAddress) l.localAddress();
    assertEquals( "127.0.0.1", a.getAddress().getHostAddress().toString() );
    assertTrue( a.getPort() > 0 && a.getPort() < 65536 );

    l.stop();
    l.waitDown( TIMEOUT );
    assertFalse( l.isStarted() );
    assertWhat( What.DOWN, lh.what );
    assertNull( lh.xsocket );
  }
View Full Code Here

Examples of etch.util.core.nio.Tcp2Listener

  /** @throws Exception */
  @Test
  public void start3() throws Exception
  {
    MyListenerHandler lh = new MyListenerHandler();
    Tcp2Listener l = new Tcp2Listener( "tcp://0.0.0.0:4998", r );
    l.setSession( lh );

    assertWhat( null, lh.what );
    assertNull( lh.xsocket );

    l.start();
    l.waitUp( TIMEOUT );
    assertTrue( l.isStarted() );

    assertWhat( What.UP, lh.what );
    assertNull( lh.xsocket );

    InetSocketAddress a = (InetSocketAddress) l.localAddress();
    if ( a.getAddress() instanceof Inet6Address )
      assertEquals( "0:0:0:0:0:0:0:0", a.getAddress().getHostAddress().toString() );
    else
      assertEquals( "0.0.0.0", a.getAddress().getHostAddress().toString() );
    assertEquals( 4998, a.getPort() );

    l.stop();
    l.waitDown( TIMEOUT );

    assertFalse( l.isStarted() );

    assertWhat( What.DOWN, lh.what );
    assertNull( lh.xsocket );
  }
View Full Code Here

Examples of etch.util.core.nio.Tcp2Listener

  /** @throws Exception */
  @Test
  public void start4() throws Exception
  {
    MyListenerHandler lh = new MyListenerHandler();
    Tcp2Listener l = new Tcp2Listener( "tcp://127.0.0.1:4996", r );
    l.setSession( lh );

    assertWhat( null, lh.what );
    assertNull( lh.xsocket );

    l.start();
    l.waitUp( TIMEOUT );

    assertTrue( l.isStarted() );

    assertWhat( What.UP, lh.what );
    assertNull( lh.xsocket );

    InetSocketAddress a = (InetSocketAddress) l.localAddress();
    assertEquals( "127.0.0.1", a.getAddress().getHostAddress().toString() );
    assertEquals( 4996, a.getPort() );

    l.stop();
    l.waitDown( TIMEOUT );

    assertFalse( l.isStarted() );

    assertWhat( What.DOWN, lh.what );
    assertNull( lh.xsocket );
  }
View Full Code Here

Examples of etch.util.core.nio.Tcp2Listener

  @Test( expected = SocketException.class )
  public void start5() throws Exception
  {
    // bad address
    MyListenerHandler lh = new MyListenerHandler();
    Tcp2Listener l = new Tcp2Listener( "tcp://1.2.3.4.5:4997", r );
    l.setSession( lh );

    assertWhat( null, lh.what );
    assertNull( lh.xsocket );

    l.start();
  }
View Full Code Here

Examples of etch.util.core.nio.Tcp2Listener

  /** @throws Exception */
  @Test
  public void accept1() throws Exception
  {
    MyListenerHandler lh = new MyListenerHandler();
    Tcp2Listener l = new Tcp2Listener( "tcp://0.0.0.0:4995", r );
    l.setSession( lh );

    l.start();
    l.waitUp( TIMEOUT );

    Socket s = new Socket( "127.0.0.1", 4995 );
    assertWhat( What.ACCEPTED, lh.what );
    assertNotNull( lh.xsocket );

    // verify they are connected to each other

    assertEquals( s.getLocalSocketAddress(), lh.xsocket.socket().getRemoteSocketAddress() );
    assertEquals( s.getRemoteSocketAddress(), lh.xsocket.socket().getLocalSocketAddress() );

    // verify they can talk to each other

    s.getOutputStream().write( 23 );
    s.getOutputStream().flush();
    assertEquals( 23, read( lh.xsocket ) );

    s.getOutputStream().write( 67 );
    s.getOutputStream().flush();
    assertEquals( 67, read( lh.xsocket ) );

    write( lh.xsocket, 24 );
    assertEquals( 24, s.getInputStream().read() );

    write( lh.xsocket, 73 );
    assertEquals( 73, s.getInputStream().read() );

    // shut 'em down.

    s.close();
    lh.xsocket.close();

    l.stop();
    l.waitDown( TIMEOUT );
  }
View Full Code Here

Examples of etch.util.core.nio.Tcp2Listener

  /** @throws Exception */
  @Test
  public void accept2() throws Exception
  {
    MyOtherListenerHandler lh = new MyOtherListenerHandler();
    Tcp2Listener l = new Tcp2Listener( "tcp://0.0.0.0:0?TcpListener.backlog=100", r );
    l.setSession( lh );

    l.start();
    l.waitUp( TIMEOUT );

    int port = ((InetSocketAddress) l.localAddress()).getPort();

    int n = 1000;

    for (int i = 0; i < n; i++)
      new Socket( "127.0.0.1", port ).close();

    // wait for things to settle down...
    Thread.sleep( 100 );

    assertEquals( n, lh.accepted );

    l.stop();
    l.waitDown( TIMEOUT );
  }
View Full Code Here

Examples of org.apache.etch.util.core.nio.Tcp2Listener

  public Transport<ServerFactory> newListener( final String uri,
    final Resources resources ) throws Exception
  {
    URL u = new URL( uri );
   
    Transport<SessionListener<SocketChannel>> l = new Tcp2Listener( u,
      resources );
   
    return new MySessionListener( l, uri, resources );
  }
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.