Example #1
1
  public void startClient(String inputFile) throws IOException {
    Socket socket = new Socket(Server.SERVER, Server.PORT);
    OutputStream out = socket.getOutputStream();
    InputStream in = socket.getInputStream();

    Reader fin = new FileReader(inputFile);
    Writer fout = new FileWriter(new Date().getTime() + "-" + randomGenerator.nextInt() + ".txt");

    try {
      while (fin.ready()) {
        Vector v1 = Vectors.readVector(fin);
        Vector v2 = Vectors.readVector(fin);

        Vectors.outputVector(v1, out);
        Vectors.outputVector(v2, out);

        Vector v3 = Vectors.inputVector(in);
        Vectors.writeVector(v3, fout);
      }
    } catch (EOFException e) {
    } finally {
      out.close();
      fout.close();
    }
  }
  public void loop() throws IOException {
    try {
      while (true) {
        Vector v1 = Vectors.inputVector(in);
        Vector v2 = Vectors.inputVector(in);

        v1.sum(v2);
        Vectors.outputVector(v1, out);
      }
    } catch (IncompatibleVectorSizesException e) {
      System.out.println("Vectors with incompatible sizes received");
    } catch (IOException ex) {
    } finally {
      out.close();
    }
  }