From 4826af957608a54e4492815551f39ac543258fd1 Mon Sep 17 00:00:00 2001
From: jestin
Date: Mon, 6 Aug 2001 14:33:34 +0000
Subject: Adding multicast ( IvyWatcher ), adding the new IvyDaemon program,
removing the debug code in Probe, and who knows what I've done in IvyClient ?
---
src/IvyDaemon.java | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
create mode 100644 src/IvyDaemon.java
(limited to 'src/IvyDaemon.java')
diff --git a/src/IvyDaemon.java b/src/IvyDaemon.java
new file mode 100644
index 0000000..09367c6
--- /dev/null
+++ b/src/IvyDaemon.java
@@ -0,0 +1,101 @@
+/**
+ * sample implementation of an Ivy Daemon, like ivyd.
+ * @author Yannick Jestin
+ * @author http://www.tls.cena.fr/products/ivy/
+ */
+package fr.dgac.ivy ;
+
+import java.io.*;
+import java.net.*;
+import gnu.getopt.Getopt;
+
+/**
+ * toy tool to send anonymous messages to an Ivy bus through a simple tcp
+ * socket.
+ * IvyDaemon runs in the background and forwards all the incoming trafic to
+ * the bus, line by line. The default port is 3456.
+ *
+ * @author Yannick Jestin
+ * @author http://www.tls.cena.fr/products/ivy/
+ */
+class IvyDaemon implements Runnable {
+
+ public static int DEFAULT_SERVICE_PORT = 3456 ;
+ ServerSocket serviceSocket;
+ boolean isRunning=false;
+ Ivy bus;
+
+ public static void main(String[] args) {
+ Getopt opt = new Getopt("IvyDaemon",args,"b:dp:");
+ int c;
+ int servicePort = DEFAULT_SERVICE_PORT;
+ String domain=Ivy.DEFAULT_DOMAIN;
+ while ((c = opt.getopt()) != -1) switch (c) {
+ case 'b':
+ domain=opt.getOptarg();
+ break;
+ case 'd':
+ System.setProperty("IVY_DEBUG","yes");
+ break;
+ case 'p':
+ String s="";
+ try {
+ servicePort = Integer.parseInt(s=opt.getOptarg());
+ } catch (NumberFormatException nfe) {
+ System.out.println("Invalid port number: " + s +
+ "switching to default port "+servicePort);
+ }
+ break;
+ default:
+ }
+ IvyDaemon d = new IvyDaemon(domain,servicePort);
+ }
+
+ IvyDaemon(String domain,int servicePort) {
+ // connexion to the Bus
+ try {
+ bus=new Ivy("IvyDaemon","IvyDaemon ready",null);
+ System.out.println("broadcasting on "+domain);
+ bus.start(domain);
+ serviceSocket = new ServerSocket(servicePort) ;
+ System.out.println("listening on "+servicePort);
+ isRunning=true;
+ (new Thread(this)).start(); // loops on the service Socket, awaiting connexion
+ } catch (IvyException ie) {
+ System.out.println("Caught an exception. quitting. "+ie.getMessage());
+ } catch (IOException ioe) {
+ System.out.println("Caught an IOexception. quitting. "+ioe.getMessage());
+ }
+ }
+
+ /*
+ * the service socket reader.
+ * it could be a thread, but as long as we've got one ....
+ */
+ public void run() {
+ while(isRunning){
+ try {
+ Socket socket = serviceSocket.accept();
+ new SubReader(
+ new BufferedReader(new InputStreamReader(socket.getInputStream())));
+ } catch( IOException e ) {
+ System.out.println("DEBUG TCP socket reader caught an exception " + e.getMessage());
+ }
+ }
+ }
+
+ class SubReader extends Thread {
+ BufferedReader in;
+ SubReader(BufferedReader in) {this.in=in;start();}
+ public void run() {
+ String msg = null;
+ try {
+ while ( ((msg=in.readLine()) != null )) { bus.sendMsg(msg); }
+ } catch (IOException ioe) {
+ System.out.println("exception ..." + ioe.getMessage());
+ }
+ }
+ } // subclass SubReader
+
+} // class IvyDaemon
+// EOF
--
cgit v1.1