FileDocCategorySizeDatePackage
PipedServer.javaAPI DocExample1448Sun Feb 01 14:38:28 GMT 1998dcj.examples

PipedServer

public class PipedServer extends Thread
Source code from "Java Distributed Computing", by Jim Farley. Class: PipedServer Example: 2-5 Description: The other end of a piped connection between two threads.

Fields Summary
PipedInputStream
pin
PipedOutputStream
pout
Constructors Summary
public PipedServer(PipedInputStream in, PipedOutputStream out)

    pin = in;
    pout = out;
  
Methods Summary
public voidrun()

    // 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();