Esempio n. 1
1
 public void Start(string[] args)
 {
     registry = new Registry();
     if (!registry.Register(this))
     {
         Console.WriteLine("Error registering service.");
         return;
     }
     Console.WriteLine("Registered service.");
     try
     {
         TcpClient tcpclient = new TcpClient();
         if (args.Count() != 2)
             throw new Exception("Argument must contain a publishing ip and port. call with: 127.0.0.1 12345");
         tcpclient.Connect(args[0], Int32.Parse(args[1]));
         StreamReader sr = new StreamReader(tcpclient.GetStream());
         string data;
         while ((data = sr.ReadLine()) != null)
         {
             Console.WriteLine("Raw data: " + data);
             if (RawAisData != null)
                 RawAisData(data);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message + e.StackTrace);
         Console.WriteLine("Press enter");
         Console.ReadLine();
     }
 }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            // Get console quit key press events.
            Console.CancelKeyPress += CancelKeyPressHandler;

            // Create registry client for registry at address tcp://localhost:5555.
            using(Registry registry = new Registry("tcp://localhost:5555")) {
                // Register our hello world responder objects with the registry.
                HelloWorldResponder responder1 = new HelloWorldResponder(1);
                HelloWorldResponder responder2 = new HelloWorldResponder(2);
                HelloWorldResponder responder3 = new HelloWorldResponder(3);

                if(registry.Register("HelloWorldResponder1", responder1))
                    Console.WriteLine("Registered HelloWorldResponder1");
                else {
                    Console.WriteLine("Failed to register HelloWorldResponder 1");
                    return;
                }
                if(registry.Register("HelloWorldResponder2", responder2))
                    Console.WriteLine("Registered HelloWorldResponder2");
                else {
                    Console.WriteLine("Failed to register HelloWorldResponder2");
                    return;
                }
                if(registry.Register("HelloWorldResponder3", responder3))
                    Console.WriteLine("Registered HelloWorldResponder3");
                else {
                    Console.WriteLine("Failed to register HelloWorldResponder3");
                    return;
                }

                // Program loop
                while(!_quit) {
                    // Emit an event in the service.
                    responder1.SomethingHappened();
                    responder3.SomethingHappened();

                    // Receive RPC calls
                    // TODO: Optionally let the library take care of this.
                    registry.Update();

                    Thread.Sleep(100);
                }
            }
        }
Esempio n. 3
0
 public void Start()
 {
     registry = new Registry();
     if (!registry.Register(this))
     {
         Console.WriteLine("Error registering service.");
         return;
     }
     Console.WriteLine("Registered service.");
     Service rawDataPublisher = null;
     while (rawDataPublisher == null && !quit)
         rawDataPublisher = registry.GetServiceByType("RawAisDataPublisher");
     if (!quit)
         rawDataPublisher.Published += RAWAisDataRecieved;
     while (!quit)
         registry.Update();
     registry.Unregister(this);
 }