byte expected2[] = { 't', 'e', 's', 't', '2' };
openConnections();
PipedOutputStream po = new PipedOutputStream();
PipedInputStream pi = new PipedInputStream(po);
OutputStream os = server1.getOutputStream();
OutputStream ostc = tc1.getOutputStream();
tc1.registerSpyStream(po);
os.write("test1".getBytes());
os.flush();
Thread.sleep(1000);
byte buffer[] = new byte[5];
if(pi.available() == 5)
{
pi.read(buffer);
if(equalBytes(buffer, expected1))
test1spy_ok = true;
}
ostc.write("test2".getBytes());
ostc.flush();
Thread.sleep(1000);
if(pi.available() == 5)
{
pi.read(buffer);
if(equalBytes(buffer, expected2))
test2spy_ok = true;
}
tc1.stopSpyStream();
os.write("test1".getBytes());
os.flush();
ostc.write("test2".getBytes());
ostc.flush();
Thread.sleep(1000);
if(pi.available() == 0)
{
stopspy_ok = true;
}
closeConnections();