Exemplo n.º 1
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 {
   out.write(10);
   if (esocket == null) {
     final int eport = Integer.parseInt(receive());
     // initialize event socket
     esocket = new Socket();
     esocket.connect(new InetSocketAddress(ehost, eport), 5000);
     final OutputStream os = esocket.getOutputStream();
     receive(in, os);
     os.write(0);
     os.flush();
     final InputStream is = esocket.getInputStream();
     is.read();
     listen(is);
   }
   send(name);
   info = receive();
   if (!ok()) throw new IOException(info);
   notifiers.put(name, notifier);
 }
Exemplo n.º 2
0
 /**
  * Checks the next success flag.
  *
  * @return value of check
  * @throws IOException Exception
  */
 boolean ok() throws IOException {
   out.flush();
   return in.read() == 0;
 }
Exemplo n.º 3
0
 /**
  * Closes the session.
  *
  * @throws IOException Exception
  */
 public void close() throws IOException {
   send("exit");
   out.flush();
   if (esocket != null) esocket.close();
   socket.close();
 }