FileDocCategorySizeDatePackage
PipedClient.javaAPI DocExample1467Thu Jan 08 22:42:04 GMT 1998dcj.examples

PipedClient

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

Fields Summary
PipedInputStream
pin
PipedOutputStream
pout
Constructors Summary
public PipedClient(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);

    // Say hello to the server...
    try
      {
        System.out.println("PipedClient: Writing greeting to server...");
        dout.writeChars("hello from PipedClient\n");
      }
    catch (IOException e)
      {
        System.out.println("PipedClient: Couldn't get response.");
        System.exit(1);
      }

    // See if it says hello back...
    try
      {
        System.out.println("PipedClient: Reading response from server...");
        String response = din.readLine();
        System.out.println("PipedClient: Server said: \""
                           + response + "\"");
      }
    catch (IOException e)
      {
        System.out.println("PipedClient: Failed to connect to peer.");
      }

    stop();