/** @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 );
}