Exemple #1
0
        public async Task Error_Callback_Should_Be_Executed_When_Serializer_Throws_An_Exception()
        {
            var serverErrorEvent = new AutoResetEvent(false);

            var server = new UdpBinding(new IPEndPoint(IPAddress.Any, 1701), new ExceptionSerializer());

            server.IoCompleted += (sender, e) => Debug.WriteLine(e.LastOperation);
            server.Error       += (sender, e) =>
            {
                serverErrorEvent.Set();
            };

            var result = server.ListenAsync();

            Assert.IsTrue(result);

            var client = new UdpBinding(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1701), new TestSerializer());

            client.IoCompleted += (sender, e) => Debug.WriteLine(e.LastOperation);

            await client.ConnectAsync();

            await client.SendAsync(new TestPacket());

            Assert.IsTrue(serverErrorEvent.WaitOne(TimeSpan.FromSeconds(3)));
        }
Exemple #2
0
        public async Task Client_Should_Receive_Package_When_Server_Responds()
        {
            var serverReceivedEvent = new AutoResetEvent(false);
            var clientReceivedEvent = new AutoResetEvent(false);

            var server = new UdpBinding(new IPEndPoint(IPAddress.Any, 1700), new TestSerializer());

            server.IoCompleted    += (sender, e) => Debug.WriteLine(e.LastOperation);
            server.PacketReceived += async(sender, e) =>
            {
                serverReceivedEvent.Set();

                await e.Binding.SendAsync(e.Packet);
            };

            var result = server.ListenAsync();

            Assert.IsTrue(result);

            var client = new UdpBinding(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1700), new TestSerializer());

            client.IoCompleted    += (sender, e) => Debug.WriteLine(e.LastOperation);
            client.PacketReceived += (sender, e) => clientReceivedEvent.Set();

            await client.ConnectAsync();

            await client.SendAsync(new TestPacket());

            Assert.IsTrue(serverReceivedEvent.WaitOne(TimeSpan.FromSeconds(3)));

            Assert.IsTrue(clientReceivedEvent.WaitOne(TimeSpan.FromSeconds(3)));
        }
Exemple #3
0
        static void Main(string[] args)
        {
            string      serviceAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding  myBinding      = new UdpBinding();
            ServiceHost host           = new ServiceHost(typeof(StockTickerService), new Uri(serviceAddress));

            host.AddServiceEndpoint(typeof(IStockTicker), myBinding, "");
            //ServiceMetadataBehavior smb = (ServiceMetadataBehavior)host.Description.Behaviors.Find<ServiceMetadataBehavior>();
            ////if (smb == null)
            ////{
            ////    smb = new ServiceMetadataBehavior();
            ////    //smb.HttpGetEnabled = true;
            ////    host.Description.Behaviors.Add(smb);
            ////}
            //  if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
            //      {
            //           ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            //           behavior.HttpGetEnabled = true;
            //           behavior.HttpGetUrl = new Uri("http://224.0.0.1:40000");
            //           host.Description.Behaviors.Add(behavior);
            //      }


            host.Open();
            Console.WriteLine("Start receiving stock information");
            Console.WriteLine("{0} is up and running with following endpoint(s)-", host.Description.ServiceType);
            Console.ReadLine();
        }
        public async Task Meter_Should_Have_The_Address_Changed_When_Meter_Address_Is_Reconfigured()
        {
            var binding = new UdpBinding(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT), new MeterbusFrameSerializer());

            var master = new MBusMaster(binding);

            await master.SetMeterAddress(0x0a, 0x09);
        }
        public async Task Meter_Scanner_Should_Find_Meter_When_Meter_Is_Connected_To_Collector()
        {
            var binding = new UdpBinding(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT), new MeterbusFrameSerializer());

            var master = new MBusMaster(binding);

            master.Meter += (sender, e) => Debug.WriteLine($"Found meter on address {e.Address.ToString("x2")}.");

            await master.Scan(new byte[] { 0x09, 0x0a, 0x0b }, TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS));
        }
        public async Task Meter_Should_Respond_When_Pinging_The_Meter()
        {
            var binding = new UdpBinding(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT), new MeterbusFrameSerializer());

            var master = new MBusMaster(binding);

            var result = await master.Ping(0x0a, TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS));

            Assert.IsTrue(result);
        }
Exemple #7
0
        private void button5_Click(object sender, EventArgs e)
        {
            var bind = new UdpBinding();

            var cf = new ChannelFactory <IBurgerService>(bind, "soap.udp://localhost:4");

            var client = cf.CreateChannel();

            dataGridView1.DataSource = client.GetBurgers();
        }
        static void Main(string[] args)
        {
            string      serviceAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding  myBinding      = new UdpBinding();
            ServiceHost host           = new ServiceHost(typeof(ServiceUdp), new Uri(serviceAddress));

            host.AddServiceEndpoint(typeof(IServiceUdp), myBinding, string.Empty);
            host.Open();
            Console.WriteLine("Press ENTER to stop the service");
            Console.ReadLine();
            host.Close();
        }
        protected override void OnApplyConfiguration(Binding binding)
        {
            UdpBinding udpBinding = (UdpBinding)binding;

            udpBinding.DuplicateMessageHistoryLength = this.DuplicateMessageHistoryLength;
            udpBinding.MaxBufferPoolSize             = this.MaxBufferPoolSize;
            udpBinding.MaxRetransmitCount            = this.MaxRetransmitCount;
            udpBinding.MaxPendingMessagesTotalSize   = this.MaxPendingMessagesTotalSize;
            udpBinding.MaxReceivedMessageSize        = this.MaxReceivedMessageSize;
            udpBinding.MulticastInterfaceId          = this.MulticastInterfaceId;
            udpBinding.TimeToLive = this.TimeToLive;
        }
        static void Main(string[] args)
        {
            string      serviceAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding  myBinding      = new UdpBinding();
            ServiceHost host           = new ServiceHost(typeof(StockTickerService), new Uri(serviceAddress));

            host.AddServiceEndpoint(typeof(IStockTicker), myBinding, "");

            host.Open();
            Console.WriteLine("Start receiving stock information");
            Console.WriteLine("{0} is up and running with following endpoint(s)-", host.Description.ServiceType);
            Console.ReadLine();
        }
        protected internal override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            UdpBinding udpBinding = (UdpBinding)binding;

            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.DuplicateMessageHistoryLength, udpBinding.DuplicateMessageHistoryLength);
            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.MaxBufferPoolSize, udpBinding.MaxBufferPoolSize);
            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.MaxRetransmitCount, udpBinding.MaxRetransmitCount);
            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.MaxPendingMessagesTotalSize, udpBinding.MaxPendingMessagesTotalSize);
            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.MaxReceivedMessageSize, udpBinding.MaxReceivedMessageSize);
            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.MulticastInterfaceId, udpBinding.MulticastInterfaceId);
            this.SetPropertyValueIfNotDefaultValue(UdpTransportConfigurationStrings.TimeToLive, udpBinding.TimeToLive);
        }
        public async Task Meter_Telemetry_Should_Be_Retrieved_When_Querying_The_Collector()
        {
            var binding = new UdpBinding(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT), new MeterbusFrameSerializer());

            var master = new MBusMaster(binding);

            var response = await master
                           .RequestData(0x0a, TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS));

            response = await master
                       .RequestData(0x0a, TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS));

            Assert.IsNotNull(response);
        }
        public async Task Meter_Should_Respond_With_Ack_When_Sending_SND_NKE()
        {
            var resetEvent = new AutoResetEvent(false);

            var binding = new UdpBinding(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT), new MeterbusFrameSerializer());

            binding.PacketReceived += (sender, e) => resetEvent.Set();

            await binding.ConnectAsync();

            await binding.SendAsync(new ShortFrame((byte)ControlMask.SND_NKE, 0x0a));

            Assert.IsTrue(resetEvent.WaitOne(TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS)));
        }
Exemple #14
0
        static void Main(string[] args)
        {
            string     serviceAddress       = "soap.udp://224.0.0.1:40000";
            UdpBinding myBinding            = new UdpBinding();
            ChannelFactory <IServiceUdp> cf = new ChannelFactory <IServiceUdp>(myBinding,
                                                                               new EndpointAddress(serviceAddress));
            IServiceUdp serv = cf.CreateChannel();

            while (true)
            {
                Console.WriteLine(serv.GetTime());
                Thread.Sleep(1000);
            }
            Console.ReadKey();
        }
Exemple #15
0
        public Uri ListenForCollaborationRequests()
        {
            if (collaborationRequestsHost != null)
            {
                throw new InvalidOperationException("Already listening for collaboration requests");
            }
            var localAddress = networkAddress.GetLocalAddress();

            //Start listening for incoming collaboration requests
            var        serviceAddress = new Uri($"soap.udp://{localAddress}:{broadcastPort}");
            UdpBinding udpBinding     = new UdpBinding();

            collaborationRequestsHost = new ServiceHost(new CollaborationRequestService(this), serviceAddress);
            collaborationRequestsHost.AddServiceEndpoint(typeof(ICollaborationRequestService), udpBinding, string.Empty);
            collaborationRequestsHost.Open();
            return(serviceAddress);
        }
Exemple #16
0
        static void Main(string[] args)
        {
            string     baseAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding myBinding   = new UdpBinding();
            ChannelFactory <IStockTicker> factory = new ChannelFactory <IStockTicker>(myBinding, new EndpointAddress(baseAddress));
            IStockTicker proxy = factory.CreateChannel();

            while (true)
            {
                // This will continue to mulicast stock information
                proxy.SendStockInfo(GetStockInfo());
                int x = proxy.ResponseStockInfo(GetStockInfo());
                Console.WriteLine(String.Format("sent stock info at {0}, the cound is {1}", DateTime.Now, x));
                // Wait for one second before sending another update
                System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
            }
        }
Exemple #17
0
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw FxTrace.Exception.ArgumentNull("context");
            }

            if (context.Endpoint.Binding == null)
            {
                throw FxTrace.Exception.ArgumentNull("context.Endpoint.Binding");
            }

            BindingElementCollection bindingElements         = context.Endpoint.Binding.CreateBindingElements();
            TransportBindingElement  transportBindingElement = bindingElements.Find <TransportBindingElement>();

            if (transportBindingElement is UdpTransportBindingElement)
            {
                ImportEndpointAddress(context);
            }

            if (context.Endpoint.Binding is CustomBinding)
            {
                Binding newEndpointBinding = null;
                if (transportBindingElement is UdpTransportBindingElement)
                {
                    Binding udpBinding;
                    if (UdpBinding.TryCreate(bindingElements, out udpBinding))
                    {
                        newEndpointBinding = udpBinding;
                    }

                    if (newEndpointBinding != null)
                    {
                        newEndpointBinding.Name      = context.Endpoint.Binding.Name;
                        newEndpointBinding.Namespace = context.Endpoint.Binding.Namespace;
                        context.Endpoint.Binding     = newEndpointBinding;
                    }
                }
            }
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** WCF Host ***");

            var httpBind   = new BasicHttpBinding();
            var tcpBind    = new NetTcpBinding();
            var pipeBind   = new NetNamedPipeBinding();
            var wsHttpBind = new WSHttpBinding();
            var mqBind     = new NetMsmqBinding();
            var udpBding   = new UdpBinding();

            var host = new ServiceHost(typeof(BurgerService));

            host.AddServiceEndpoint(typeof(IBurgerService), httpBind, "http://localhost:1/");
            host.AddServiceEndpoint(typeof(IBurgerService), tcpBind, "net.tcp://localhost:2/");
            host.AddServiceEndpoint(typeof(IBurgerService), pipeBind, "net.pipe://localhost/Burger");
            host.AddServiceEndpoint(typeof(IBurgerService), wsHttpBind, "http://localhost:3/");
            host.AddServiceEndpoint(typeof(IBurgerService), udpBding, "soap.udp://localhost:4/");
            //nur One-way
            //host.AddServiceEndpoint(typeof(IBurgerService), mqBind, "net.msmq://localhost/private/Burger");


            var smb = new ServiceMetadataBehavior()
            {
                HttpGetEnabled = true,
                HttpGetUrl     = new Uri("http://localhost:1/mex")
            };

            host.Description.Behaviors.Add(smb);

            host.Open();
            Console.WriteLine("Service läuft");
            Console.ReadLine();
            host.Close();


            Console.WriteLine("Ende");
            Console.ReadLine();
        }
Exemple #19
0
        public CollaborationRequest BroadcastCollaborationRequestForFile(string filename)
        {
            var collaborationRequest = CreateRequestForFilename(filename);

            if (!SwitchCollaborationRequest(collaborationRequest))
            {
                throw new InvalidOperationException("Cannot broadcast a collaboration request now: we're already working on another collaboration");
            }

            //Create a WCF client by indicating A-B-C: Address, Binding, Contract
            //Address
            string serviceAddress = $"soap.udp://{networkAddress.BroadcastAddress}:{broadcastPort}";
            //Binding
            UdpBinding myBinding = new UdpBinding();
            //Create the ChannelFactory by indicating the Contract (i.e. the service interface)
            ChannelFactory <ICollaborationRequestService> factory = new ChannelFactory <ICollaborationRequestService>(myBinding, new EndpointAddress(serviceAddress));

            //Open the channel and send the request
            ICollaborationRequestService proxy = factory.CreateChannel();

            proxy.BroadcastCollaborationRequest(collaborationRequest);
            factory.Close();
            return(collaborationRequest);
        }
Exemple #20
0
        public PovratnaVrijednost OpenApp(byte[] encrypted)
        {
            OpenAppData decryted = (OpenAppData)AesAlg.Decrypt(encrypted, sessionKeys[Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name)]);

            Console.WriteLine("------------------ OTVARANJE SERVISA ------------------");
            Console.WriteLine("Korisnik {0} je zatrazio otvaranje novog servisa na portu {1} sa protokolom {2}", Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name)
                              , decryted.Port, decryted.Protokol);
            IIdentity       identity    = Thread.CurrentPrincipal.Identity;
            WindowsIdentity winIdentity = identity as WindowsIdentity;

            string        user   = Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name);
            List <string> groups = GetUsergroups(winIdentity.Groups);


            blackList = Restriction.ReadBlackList();

            if (Restriction.IsRestricted(blackList, decryted, user, groups))
            {
                Console.WriteLine("Korisnik nema dozvolu za otvaranje servisa na datom portu ili sa datim protokolom.");
                string pov = WCFServiceAudit.ReturnFactory().ConnectS(string.Format("{0}|{1}|{2}", user, decryted.Protokol, decryted.Port));
                Console.WriteLine("------------------ OTVARANJE NEUSPESNO ------------------");
                if (pov == "DoS")
                {
                    return(PovratnaVrijednost.DOS);
                }
                return(PovratnaVrijednost.NEMADOZ);;
            }


            if (servisi.ContainsKey(string.Format("{0}", decryted.Port)))
            {
                Console.WriteLine("Servis je vec otvoren na datom portu");
                Console.WriteLine("------------------ OTVARANJE NEUSPESNO ------------------");
                return(PovratnaVrijednost.VECOTV);
            }

            ServiceHost host = new ServiceHost(typeof(WCFService));

            if (decryted.Protokol == "UDP")
            {
                Console.WriteLine("Otvaranje UDP konekcije");
                UdpBinding binding = new UdpBinding();
                string     addr    = String.Format("soap.udp://localhost:{0}/{1}", decryted.Port, decryted.ImeMasine);
                host.AddServiceEndpoint(typeof(IWCFContract), binding, addr);
            }
            else if (decryted.Protokol == "HTTP")
            {
                Console.WriteLine("Otvaranje HTTP konekcije");
                NetHttpBinding binding = new NetHttpBinding();
                string         addr    = String.Format("http://localhost:{0}/{1}", decryted.Port, decryted.ImeMasine);
                host.AddServiceEndpoint(typeof(IWCFContract), binding, addr);
            }
            else
            {
                Console.WriteLine("Otvaranje TCP konekcije");
                NetTcpBinding binding = new NetTcpBinding();
                string        addr    = String.Format("net.tcp://localhost:{0}/{1}", decryted.Port, decryted.ImeMasine);
                host.AddServiceEndpoint(typeof(IWCFContract), binding, addr);
            }

            string key = String.Format("{0}", decryted.Port);

            servisi.Add(key, host);
            servisi[key].Open();
            Console.WriteLine("------------------ OTVARANJE USPESNO ------------------");
            return(PovratnaVrijednost.USPJEH);
        }
        public async Task Test1()
        {
            var packet = new PushDataPacket
            {
                ProtocolVersion = 1,
                Token           = 1,
                Eui             = "0000000000000001",
                Payload         = new PushDataPacketPayload
                {
                    Rxpk = new List <Rxpk>()
                    {
                        new RxpkV2
                        {
                            Time                = DateTime.UtcNow,
                            Timestamp           = GpsTime.Time,
                            RadioFrequencyChain = 1,
                            Frequency           = 868.500000,
                            CrcStatus           = CrcStatus.OK,
                            Modulation          = Modulation.LORA,
                            DataRate            = DatarateIdentifier.SF7BW125,
                            CodingRate          = CodeRate.CR_LORA_4_8,
                            Size                = 14,
                            Data                = "Wg3qoMwpJ5T372B9pxLIs0kbvUs=",
                            RadioSignals        = new List <Rsig>()
                            {
                                new Rsig
                                {
                                    Antenna                       = 0,
                                    Channel                       = 7,
                                    FineTimestamp                 = 50000,
                                    EncryptedTimestamp            = "asd",
                                    ReceivedSignalStrengthChannel = -75,
                                    LoraSignalToNoiseRatio        = 30,
                                }
                            }
                        },
                        new RxpkV2
                        {
                            Time                = DateTime.UtcNow,
                            Timestamp           = GpsTime.Time,
                            RadioFrequencyChain = 1,
                            Frequency           = 868.500000,
                            CrcStatus           = CrcStatus.OK,
                            Modulation          = Modulation.LORA,
                            DataRate            = DatarateIdentifier.SF7BW125,
                            CodingRate          = CodeRate.CR_LORA_4_8,
                            Size                = 14,
                            Data                = "Wg3qoMwpJ5T372B9pxLIs0kbvUs=",
                            RadioSignals        = new List <Rsig>()
                            {
                                new Rsig
                                {
                                    Antenna                       = 1,
                                    Channel                       = 7,
                                    FineTimestamp                 = 50000,
                                    EncryptedTimestamp            = "asd",
                                    ReceivedSignalStrengthChannel = -75,
                                    LoraSignalToNoiseRatio        = 30,
                                }
                            }
                        }
                    },
                    Stat = new StatV2
                    {
                        Lati = 46.24,
                        Long = 3.2523,
                        Alti = 100,
                        Time = DateTime.UtcNow,
                    },
                }
            };

            var resetEvent = new AutoResetEvent(false);

            var binding = new UdpBinding(new PicocellPacketSerializer());

            binding.PacketReceived += (sender, e) => resetEvent.Set();

            await binding.ConnectAsync(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT));

            await binding.SendAsync(packet);

            Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS)));
        }