Пример #1
0
 /**
  * Sends the specified stream to the server.
  *
  * @param input input stream
  * @throws IOException I/O exception
  */
 private void send(final InputStream input) throws IOException {
   final EncodingOutput eo = new EncodingOutput(sout);
   for (int b; (b = input.read()) != -1; ) eo.write(b);
   sout.write(0);
   sout.flush();
   receive(null);
 }
Пример #2
0
  /**
   * Watches an event.
   *
   * @param name event name
   * @param notifier event notification
   * @throws IOException I/O exception
   */
  public void watch(final String name, final EventNotifier notifier) throws IOException {

    sout.write(ServerCmd.WATCH.code);
    if (esocket == null) {
      sout.flush();
      final BufferInput bi = new BufferInput(sin);
      final int eport = Integer.parseInt(bi.readString());
      // initialize event socket
      esocket = new Socket();
      esocket.connect(new InetSocketAddress(ehost, eport), 5000);
      final OutputStream so = esocket.getOutputStream();
      so.write(bi.readBytes());
      so.write(0);
      so.flush();
      final InputStream is = esocket.getInputStream();
      is.read();
      listen(is);
    }
    send(name);
    sout.flush();
    receive(null);
    notifiers.put(name, notifier);
  }