// Wrap a data stream around the input and output streams
DataInputStream din = new DataInputStream(pin);
DataOutputStream dout = new DataOutputStream(pout);
// Wait for the client to say hello...
try {
System.out.println("PipedServer: Reading from client...");
String clientHello = din.readLine();
System.out.println("PipedServer: Client said: \""
+ clientHello + "\"");
}
catch (IOException e)
{
System.out.println("PipedServer: Couldn't get hello from client.");
stop();
}
// ...and say hello back.
try
{
System.out.println("PipedServer: Writing response to client...");
dout.writeChars("hello I am the server.\n");
}
catch (IOException e)
{
System.out.println("PipedServer: Failed to connect to client.");
}
stop();