示例#1
0
        private static void Main(string[] args)
        {
            var calculatorImp    = new CalculatorImp();
            var dispatcherThread = new DispatcherThread(Dispatcher.Run);

            dispatcherThread.Start();

            var server = new IpcServer <ICalculator>(calculatorImp, dispatcherThread.Dispatcher, IPAddress.Any, 62005, new JsonDotNetSerializer());

            server.ClientConnected    += OnClientConnected;
            server.ClientDisconnected += OnClientDisconnected;

            server.Listen();

            var multiCastAddress = IPAddress.Parse("239.0.0.222");
            var advertiser       = new ServiceAdvertiser <ICalculator>(multiCastAddress, 2222, TimeSpan.FromMilliseconds(1000));

            advertiser.OnAdvertisement += dt => Console.WriteLine("[{0}]", dt);

            Console.ReadLine();

            server.ClientDisconnected -= OnClientDisconnected;
            server.ClientConnected    -= OnClientConnected;


            advertiser.Dispose();
        }
        public void UnPublishService(ServiceAdvertiser advertiser, bool fRemove = false)
        {
            ThrowIfDisposed();

            WFDSvcWrapperHandle handle = advertiser.Handle;

            WiFiDirectTestLogger.Log("Unpublishing advertiser (Advertiser={0} ServiceName={1})", handle, advertiser.Advertiser.ServiceName);

            advertiser.Advertiser.Stop();

            if (fRemove)
            {
                WiFiDirectTestLogger.Log("Removing advertiser (Advertiser={0} ServiceName={1})", handle, advertiser.Advertiser.ServiceName);
                advertiser.Dispose();

                advertiserCollection.Remove(handle);
            }

            WiFiDirectTestLogger.Log("Unpublish service done (Advertiser={0})", handle);
        }
示例#3
0
        private static void Main(string[] args)
        {
            var calculatorImp = new CalculatorImp();
            var dispatcherThread = new DispatcherThread(Dispatcher.Run);
            dispatcherThread.Start();

            var server = new IpcServer<ICalculator>(calculatorImp, dispatcherThread.Dispatcher, IPAddress.Any, 62005, new JsonDotNetSerializer());
            server.ClientConnected += OnClientConnected;
            server.ClientDisconnected += OnClientDisconnected;

            server.Listen();

            var multiCastAddress = IPAddress.Parse("239.0.0.222");
            var advertiser = new ServiceAdvertiser<ICalculator>(multiCastAddress, 2222, TimeSpan.FromMilliseconds(1000));
            advertiser.OnAdvertisement += dt => Console.WriteLine("[{0}]", dt);

            Console.ReadLine();

            server.ClientDisconnected -= OnClientDisconnected;
            server.ClientConnected -= OnClientConnected;


            advertiser.Dispose();
        }