FileDocCategorySizeDatePackage
RunnableSolverClient.javaAPI DocExample1764Sat Jan 31 22:44:32 GMT 1998dcj.examples

RunnableSolverClient

public class RunnableSolverClient extends SimpleClient
Source code from "Java Distributed Computing", by Jim Farley. Class: RunnableSolverClient Example: 4-3 Description: A client that connects with a RunnableSolverServer and submits a problem for it to solve.

Fields Summary
ProblemSet
problem
Constructors Summary
public RunnableSolverClient(String host, int port, double pval)

    super(host, port);
    problem = new ProblemSet();
    problem.setValue(pval);
  
Methods Summary
public static voidmain(java.lang.String[] argv)

    if (argv.length < 3) {
      System.out.println("Usage: java RunnableSolverClient [host] [port] [problem]");
      System.exit(1);
    }

    String host = argv[0];
    int port = 3000;
    double pval = 0;
    try {
      port = Integer.parseInt(argv[1]);
      pval = Double.valueOf(argv[2]).doubleValue();
    }
    catch (NumberFormatException e) {
      System.err.println("Bad port number or problem value given.");
    }

    RunnableSolverClient client = new RunnableSolverClient(host, port, pval);
    System.out.println("Attaching client to " + host + ":" + port + "...");
    client.run();
  
public voidrun()

    try {
      DataOutputStream dout =
        new DataOutputStream(serverConn.getOutputStream());
      DataInputStream din =
        new DataInputStream(serverConn.getInputStream());

      // Send a problem...
      dout.writeChars("problem " + problem.getValue() + " ");
      // ...and read the solution
      String result = din.readLine();
    }
    catch (IOException e) {
      System.out.println("RunnableSolverClient: " + e);
      System.exit(1);
    }