コード例 #1
0
ファイル: Program.cs プロジェクト: lulzzz/TestServer
        private static void RunInteropTests(string testToRun, ICoapConfig config, EndPoint serverEndPoint)
        {
            CoapServer server = new CoapServer(config, serverEndPoint, 5683);

            switch (testToRun)
            {
            case "CoapCore":
                InteropTests.CoapCoreTests.CoapCoreTests.Setup(server);
                break;

            default:
                Console.WriteLine("Interop test name not recognized");
                Environment.Exit(1);
                break;
            }

            server.Start();

            if (AsDemon)
            {
                ExitEvent.WaitOne();
            }
            else
            {
                Console.WriteLine("Press key to exit");
                Console.ReadKey();
            }

            Environment.Exit(0);
        }
コード例 #2
0
ファイル: Callbacks.cs プロジェクト: adavidoaiei/CoAP-CSharp
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);

            _server = new CoapServer();

            //            _resource = new StorageResource(TARGET, CONTENT_1);
            //           _server.Add(_resource);

            Resource r2 = new EchoLocation("abc");

            _server.Add(r2);

            r2.Add(new EchoLocation("def"));

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
            Console.WriteLine($"Server port = {_serverPort}");

            SecurityContextSet oscoapContexts = new SecurityContextSet();

            _server.SecurityContexts.Add(SecurityContext.DeriveContext(secret, null, serverId, clientId));
            _server.SecurityContexts.OscoreEvents += ServerEventHandler;
        }
コード例 #3
0
        //    public static void Main(string[] args)
        //    {
        //        CreateHostBuilder(args).Build().Run();
        //    }

        //    public static IHostBuilder CreateHostBuilder(string[] args) =>
        //        Host.CreateDefaultBuilder(args)
        //            .ConfigureWebHostDefaults(webBuilder =>
        //            {
        //                webBuilder.UseStartup<Startup>();
        //            });
        //}

        //Servidor COAP que recibe las peticiones de la EB
        public static void Main(string[] args)
        {
            var config = CargaConfiguracion();
            int puerto = config.GetValue <int>("Puerto");

            CoapServer server = new CoapServer(puerto);

            server.Add(new RecursoPeticion());

            try
            {
                server.Start();

                Console.Write("COAP server [{0}] is listening on", server.Config.Version);
                Log.Debug($"COAP server {server.Config.Version} is listening on ");

                foreach (var item in server.EndPoints)
                {
                    Console.Write(" ");
                    Console.Write(item.LocalEndPoint);
                    Log.Information(item.LocalEndPoint.ToString());
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex.Message);
            }
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();

            Log.CloseAndFlush();
        }
コード例 #4
0
        public static void Main(String[] args)
        {
            CoapServer server = new CoapServer();

            server.Add(new HelloWorldResource("hello"));
            server.Add(new FibonacciResource("fibonacci"));
            server.Add(new StorageResource("storage"));
            server.Add(new ImageResource("image"));
            server.Add(new MirrorResource("mirror"));
            server.Add(new LargeResource("large"));
            server.Add(new CarelessResource("careless"));
            server.Add(new SeparateResource("separate"));
            server.Add(new TimeResource("time"));

            try
            {
                server.Start();

                Console.Write("CoAP server [{0}] is listening on", server.Config.Version);

                foreach (var item in server.EndPoints)
                {
                    Console.Write(" ");
                    Console.Write(item.LocalEndPoint);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
コード例 #5
0
        public static void Main(String[] args)
        {
            CoapServer server = new CoapServer();

            server.Add(new HelloWorldResource());

            try
            {
                server.Start();

                Console.Write("CoAP server [{0}] is listening on", server.Config.Version);

                foreach (var item in server.EndPoints)
                {
                    Console.Write(" ");
                    Console.Write(item.LocalEndPoint);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
コード例 #6
0
ファイル: CoAPService.cs プロジェクト: yangmain/IoTSharp
 public CoAPService(ILogger <CoAPService> logger, IServiceScopeFactory scopeFactor)
 {
     server        = new CoapServer();
     _logger       = logger;
     _serviceScope = scopeFactor.CreateScope();
     _dbContext    = _serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
     Enum.GetNames(typeof(CoApRes)).ToList().ForEach(n => server.Add(new CoApResource(n, _serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>(), _logger)));
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: malachi-iot/CoAP.Net
        static async Task Main(string[] args)
        {
            // Create a task that finishes when Ctrl+C is pressed
            var taskCompletionSource = new TaskCompletionSource <bool>();

            // Capture the Control + C event
            Console.CancelKeyPress += (s, e) =>
            {
                Console.WriteLine("Exiting");
                taskCompletionSource.SetResult(true);

                // Prevent the Main task from being destroyed prematurely.
                e.Cancel = true;
            };

            Console.WriteLine("Press <Ctrl>+C to exit");

            // Create a resource handler.
            var myHandler = new CoapResourceHandler();

            // Register a /hello resource.
            myHandler.Resources.Add(new HelloResource("/hello"));

            // Create a new CoapServer using UDP as it's base transport
            var myServer = new CoapServer(new CoapUdpTransportFactory());

            try
            {
                // Listen to all ip address and subscribe to multicast requests.
                await myServer.BindTo(new CoapUdpEndPoint(Coap.Port) { JoinMulticast = true });

                // Start our server.
                await myServer.StartAsync(myHandler, CancellationToken.None);

                Console.WriteLine("Server Started!");

                // Wait indefinitely until the application quits.
                await taskCompletionSource.Task;
            }
            catch (Exception ex)
            {
                // Canceled tasks are expected, safe to ignore.
                if (ex is TaskCanceledException)
                {
                    return;
                }

                Console.WriteLine($"Exception caught: {ex}");

                Console.WriteLine($"Press <Enter> to exit");
                Console.Read();
            }
            finally
            {
                Console.WriteLine("Shutting Down Server");
                await myServer.StopAsync(CancellationToken.None);
            }
        }
コード例 #8
0
ファイル: CoAPService.cs プロジェクト: neoayi/IoTSharp
 public CoAPService(ILogger <CoAPService> logger, IServiceScopeFactory scopeFactor, IOptions <AppSettings> options, IMsgQueue queue)
 {
     _settings     = options.Value;
     server        = new CoapServer(_settings.CoapServer);
     _logger       = logger;
     _serviceScope = scopeFactor.CreateScope();
     _dbContext    = _serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
     Enum.GetNames(typeof(CoApRes)).ToList().ForEach(n => server.Add(new CoApResource(n, _serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>(), _logger, queue)));
 }
コード例 #9
0
        private void CreateServer()
        {
            _server = new CoapServer();
            CoAPEndPoint endpoint = new CoAPEndPoint(_serverPort, _config);

            _server.AddEndPoint(endpoint);
            _server.MessageDeliverer = new MessageDeliverer(this);
            _server.Start();
        }
コード例 #10
0
 public void SetupServer()
 {
     Log.LogManager.Level = Log.LogLevel.Fatal;
     _config = new CoapConfig();
     _server = new CoapServer();
     CoAPEndPoint endpoint = new CoAPEndPoint(_serverPort, _config);
     _server.AddEndPoint(endpoint);
     _server.Add(new TestResource(TARGET));
     _server.Start();
 }
コード例 #11
0
ファイル: MessageTypeTest.cs プロジェクト: rlusian1/CoAP.NET
 public void SetupServer()
 {
     Log.LogManager.Level = Log.LogLevel.Fatal;
     CoAPEndPoint endpoint = new CoAPEndPoint();
     _server = new CoapServer();
     _server.Add(new AccResource());
     _server.Add(new NoAccResource());
     _server.AddEndPoint(endpoint);
     _server.Start();
     _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
 }
コード例 #12
0
        public void SetupServer()
        {
            Log.LogManager.Level = Log.LogLevel.Fatal;
            _config = new CoapConfig();
            _server = new CoapServer();
            CoAPEndPoint endpoint = new CoAPEndPoint(_serverPort, _config);

            _server.AddEndPoint(endpoint);
            _server.Add(new TestResource(TARGET));
            _server.Start();
        }
コード例 #13
0
        private void CreateServer()
        {
            _server = new CoapServer();
            CoAPEndPoint endpoint = new CoAPEndPoint(_serverPort, _config);

            _server.AddEndPoint(endpoint);
            _server.MessageDeliverer = new MessageDeliverer(this);
            _server.SecurityContexts.Add(SecurityContext.DeriveContext(secret, null, serverId, clientId));
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #14
0
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);

            _resource = new StorageResource(TARGET, CONTENT_1);
            _server   = new CoapServer();
            _server.Add(_resource);

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #15
0
        public void SetupServer()
        {
            Log.LogManager.Level = Log.LogLevel.Fatal;
            CoAPEndPoint endpoint = new CoAPEndPoint();

            _server = new CoapServer();
            _server.Add(new AccResource());
            _server.Add(new NoAccResource());
            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #16
0
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new DTLSEndPoint(null, UserKeys, 0);

            _resource = new HelloResource("Hello1");
            _server   = new CoapServer();
            _server.Add(_resource);

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #17
0
ファイル: Test_PubSubResource.cs プロジェクト: lulzzz/PubSub
        public void SetupServer()
        {
            _server = new CoapServer();
            CoAPEndPoint ep = new CoAPEndPoint(0);

            _server.AddEndPoint(ep);

            Resource r1 = new PubSubResource("ps", true);

            _server.Add(r1);
            _server.Start();

            _port = ((System.Net.IPEndPoint)ep.LocalEndPoint).Port;
        }
コード例 #18
0
ファイル: OneServer.cs プロジェクト: jimsch/COAP-Sandbox
        private void CreateServer()
        {
            _server = new CoapServer();

            TcpEndPoint endpoint = new TcpEndPoint();

            _server.AddEndPoint(endpoint);

            _server.Add(new HelloWorldResource("hello"));

            _server.Start();

            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #19
0
ファイル: Main.cs プロジェクト: shouxian92/final-year-project
        private void btnNext_Click(object sender, EventArgs e)
        {
            iSelectedHall = (ComboBoxItem)cmbHalls.SelectedItem;
            lblHall.Text  = iSelectedHall.Text.ToUpper();

            pnlProgress.Visible      = true;
            pnlHallSelection.Visible = false;
            pnlSeatNumber.Visible    = false;
            setInstruction(INSTR_SCAN);


            CoapServer server = new CoapServer();

            server.Add(new LookupMatricCardResource(this));

            try
            {
                server.Start();

                Console.Write("CoAP server [{0}] is listening on", server.Config.Version);

                foreach (var item in server.EndPoints)
                {
                    Console.Write(" ");
                    Console.Write(item.LocalEndPoint);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            if (LOCAL)
            {
                tmrApp          = new System.Windows.Forms.Timer();
                tmrApp.Interval = 1000;
                tmrApp.Tick    += new EventHandler(_delayTimer2_Elapsed);
                tmrApp.Start();
            }
            else
            {
                sm132.OpenPort("COM3", 19200);
                tmrNfc         = new System.Windows.Forms.Timer();
                tmrNfc.Tick   += new EventHandler(tmrNfc_Tick);
                tmrNfc.Enabled = true;
                seekTag();
            }
        }
コード例 #20
0
ファイル: ExampleServer.cs プロジェクト: jimsch/COAP-Sandbox
        public static void Main(String[] args)
        {
            KeySet keys = new KeySet();

            OneKey key = new OneKey();

            key.Add(CoseKeyKeys.KeyType, COSE.GeneralValues.KeyType_Octet);
            key.Add(CoseKeyKeys.KeyIdentifier, CBORObject.FromObject(Encoding.UTF8.GetBytes("password")));
            key.Add(CoseKeyParameterKeys.Octet_k, CBORObject.FromObject(Encoding.UTF8.GetBytes("sesame")));
            keys.AddKey(key);


            CoapServer server = new CoapServer();

            // server.AddEndPoint(new TcpEndPoint(5683));
            server.AddEndPoint(new DTLSEndPoint(null, keys, 5684));

            server.Add(new HelloWorldResource("hello"));
            server.Add(new FibonacciResource("fibonacci"));
            server.Add(new StorageResource("storage"));
            server.Add(new ImageResource("image"));
            server.Add(new MirrorResource("mirror"));
            server.Add(new LargeResource("large"));
            server.Add(new CarelessResource("careless"));
            server.Add(new SeparateResource("separate"));
            server.Add(new TimeResource("time"));

            try
            {
                server.Start();

                Console.Write("CoAP server [{0}] is listening on", server.Config.Version);

                foreach (var item in server.EndPoints)
                {
                    Console.Write(" ");
                    Console.Write(item.LocalEndPoint);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            server.Stop();
        }
コード例 #21
0
ファイル: TlssX509.cs プロジェクト: Com-AugustCellars/TCP
        private void CreateServer()
        {
            TlsKeyPairSet allKeys = new TlsKeyPairSet();
            allKeys.AddKey(X509Key);
            TLSEndPoint endpoint = new TLSEndPoint(allKeys, new KeySet(), 0);
            endpoint.TlsEventHandler += ServerTlsEvents;

            _resource = new TlsX509.HelloResource("Hello1");
            _server = new CoapServer();
            _server.Add(_resource);

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #22
0
ファイル: CoapCoreTests.cs プロジェクト: lulzzz/TestServer
        public static void Setup(CoapServer server)
        {
            IResource r = new TestResource();

            server.Add(r);

            server.Add(new LongPath());
            server.Add(new Query());
            server.Add(new Separate());
            server.Add(new LargeResource("large"));
            server.Add(new LargeResource("large_update"));
            server.Add(new LargeResource("large_create"));
            server.Add(new TimeResource("obs", 5));
            server.Add(new MultiFormat());
            server.Add(new LocationQuery());
        }
コード例 #23
0
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);

            _resource = new TestResource(NAME_1, PAYLOAD);
            _server   = new CoapServer();
            _server
            .Add(new Resource(RES_A)
                 .Add(new Resource(RES_AA)
                      .Add(_resource
                           .Add(new TestResource(CHILD, CHILD_PAYLOAD)))));

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #24
0
        private void CreateServer()
        {
            _config = new CoapConfig {
                NonTimeout = 10             // 10 ms
            };

            _resource  = new ObserveTests2.ObserveResource(target1);
            _resource2 = new ObserveTests2.ObserveResource(target2);
            _server    = new CoapServer(_config);
            _server.Add(_resource);
            _server.Add(_resource2);
            IEndPoint endpoint = Pump.AddEndPoint("server #1", MockMessagePump.ServerAddress, _config, new Type[] { typeof(ObserveLayer), typeof(TokenLayer), typeof(ReliabilityLayer) });

            _server.AddEndPoint(endpoint);
            _server.Start();
        }
コード例 #25
0
        public void SetupServer()
        {
            Log.LogManager.Level = Log.LogLevel.Fatal;

            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
                _serverPort = ((IPEndPoint)socket.LocalEndPoint).Port;
                socket.Close();
            }

            _server1 = new CoapServer(_serverPort);
            _server1.Add(new TestResource("ress", SERVER_1_RESPONSE));

            _server2 = new CoapServer(_serverPort);
            _server2.Add(new TestResource("ress", SERVER_2_RESPONSE));
        }
コード例 #26
0
        private void CreateServer()
        {
            _config            = new CoapConfig();
            _config.NonTimeout = 10; // 10 ms

            CoAPEndPoint endpoint = new CoAPEndPoint(0, _config);

            _resource  = new ObserveResource(target1);
            _resource2 = new ObserveResource(target2);
            _server    = new CoapServer(_config);
            _server.Add(_resource);
            _server.Add(_resource2);

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: lulzzz/PubSub
        static void Main(string[] args)
        {
            LogManager.Instance = new FileLogManager(Console.Out);
            LogManager.Level    = LogLevel.All;

            CoapServer server = new CoapServer();

            PubSubResource pubsub = new PubSubResource("ps");

            server.Add(pubsub);

            server.Start();

            Console.ReadLine();

            server.Stop();
        }
コード例 #28
0
ファイル: StartStopTest.cs プロジェクト: rlusian1/CoAP.NET
        public void SetupServer()
        {
            Log.LogManager.Level = Log.LogLevel.Fatal;

            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
                _serverPort = ((IPEndPoint)socket.LocalEndPoint).Port;
                socket.Close();
            }

            _server1 = new CoapServer(_serverPort);
            _server1.Add(new TestResource("ress", SERVER_1_RESPONSE));

            _server2 = new CoapServer(_serverPort);
            _server2.Add(new TestResource("ress", SERVER_2_RESPONSE));
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: rlusian1/CoAP.NET
        static void Main(string[] args)
        {
            ForwardingResource coap2coap = new ProxyCoapClientResource("coap2coap");
            ForwardingResource coap2http = new ProxyHttpClientResource("coap2http");

            // Create CoAP Server on PORT with proxy resources form CoAP to CoAP and HTTP
            CoapServer coapServer = new CoapServer(CoapConfig.Default.DefaultPort);
            coapServer.Add(coap2coap);
            coapServer.Add(coap2http);
            coapServer.Add(new TargetResource("target"));
            coapServer.Start();

            ProxyHttpServer httpServer = new ProxyHttpServer(CoapConfig.Default.HttpPort);
            httpServer.ProxyCoapResolver = new DirectProxyCoAPResolver(coap2coap);

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
コード例 #30
0
ファイル: CoapClientTest.cs プロジェクト: ulfendk/CoAP-CSharp
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);

            _resource = new StorageResource(TARGET, CONTENT_1);
            _server   = new CoapServer();
            _server.Add(_resource);

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;

            Resource r2 = new EchoLocation("abc");

            _server.Add(r2);

            r2.Add(new EchoLocation("def"));
        }
コード例 #31
0
        public static void Main(String[] args)
        {
            string ipadress = args[0];
            string port     = args[1];
            int    portInt  = Int32.Parse(port);

            // System.Net.EndPoint endpoint= System.Net.EndPoint  (ipadress, portInt);

            //System.Net.EndPoint endPoint = System.Net.IPAddress.Parse(ipadress);
            System.Net.IPAddress ip     = System.Net.IPAddress.Parse(ipadress);
            CoapServer           server = new CoapServer();

            server.AddEndPoint(ip, portInt);

            server.Add(new HelloWorldResource("hello"));
            server.Add(new FibonacciResource("fibonacci"));
            server.Add(new StorageResource("Devices"));
            server.Add(new ImageResource("image"));
            server.Add(new MirrorResource("mirror"));
            server.Add(new LargeResource("large"));
            server.Add(new CarelessResource("careless"));
            server.Add(new SeparateResource("separate"));
            server.Add(new TimeResource("time"));

            try
            {
                server.Start();
                Console.Write("CoAP server [{0}] is listening on", server.Config.Version);

                foreach (var item in server.EndPoints)
                {
                    Console.Write(" ");
                    Console.Write(item.LocalEndPoint);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
コード例 #32
0
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);


            KeySet ks = new KeySet();

            ks.AddKey(psk);
            ks.AddKey(_clientSignKey.PublicKey());

            _resource = new EdhocResource(ks, serverSignKey);
            _server   = new CoapServer();
            _server.Add(_resource);

            _server.Add(new Hello("hello"));

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #33
0
        static void Main(string[] args)
        {
            ForwardingResource coap2coap = new ProxyCoapClientResource("coap2coap");
            ForwardingResource coap2http = new ProxyHttpClientResource("coap2http");

            // Create CoAP Server on PORT with proxy resources form CoAP to CoAP and HTTP
            CoapServer coapServer = new CoapServer(CoapConfig.Default.DefaultPort);

            coapServer.Add(coap2coap);
            coapServer.Add(coap2http);
            coapServer.Add(new TargetResource("target"));
            coapServer.Start();

            ProxyHttpServer httpServer = new ProxyHttpServer(CoapConfig.Default.HttpPort);

            httpServer.ProxyCoapResolver = new DirectProxyCoAPResolver(coap2coap);

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
コード例 #34
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            CoapServer server = new CoapServer(puerto);

            server.Add(new RecursoPeticion());

            try
            {
                server.Start();

                foreach (var item in server.EndPoints)
                {
                    Log.Information($"API (CoAP Server) {server.Config.Version} is listening on {item.LocalEndPoint.ToString()}");
                }
            }
            catch (Exception ex)
            {
                Log.Fatal($"ERR API//SERVIDOR CoAP - {ex.Message}");
            }
        }
コード例 #35
0
 private void CreateServer()
 {
     _server = new CoapServer();
     CoAPEndPoint endpoint = new CoAPEndPoint(_serverPort, _config);
     _server.AddEndPoint(endpoint);
     _server.MessageDeliverer = new MessageDeliverer(this);
     _server.Start();
 }
コード例 #36
0
ファイル: Server.cs プロジェクト: CreatorDev/DeviceServer
        public void Start()
        {
            CoAP.Log.LogManager.Level = CoAP.Log.LogLevel.Error;
            int port;
            string apiPort = System.Configuration.ConfigurationManager.AppSettings["APIPort"];
            if (!int.TryParse(apiPort, out port))
                port = 14080;
            _ProcessRequestsThread = new Thread(new ThreadStart(ProcessRequests));
            if (_ProcessRequestsThread.Name == null)
                _ProcessRequestsThread.Name = "ProcessRequestsThread";
            _ProcessRequestsThread.IsBackground = true;
            _ProcessRequestsThread.Start();
            if (_CoapServer == null)
            {
                _CoapServer = new CoapServer();
                _CoapServer.MessageDeliverer = this;
                if (!SecureOnly)
                    _CoapServer.AddEndPoint(new CoAPEndPoint(new FlowChannel(Port), CoapConfig.Default));
                _SecureChannel = new FlowSecureChannel(Port + 1);
                if (System.IO.File.Exists("LWM2MServer.pem"))
                {
                    _SecureChannel.CertificateFile = "LWM2MServer.pem";
                }
                _SecureChannel.PSKIdentities = _PSKIdentities;
                _SecureChannel.SupportedCipherSuites.Add(TCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8);
                _SecureChannel.SupportedCipherSuites.Add(TCipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256);
                _SecureChannel.SupportedCipherSuites.Add(TCipherSuite.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256);
                _SecureChannel.SupportedCipherSuites.Add(TCipherSuite.TLS_PSK_WITH_AES_128_CCM_8);
                _SecureChannel.SupportedCipherSuites.Add(TCipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256);
                _SecureChannel.ValidatePSK += new EventHandler<ValidatePSKEventArgs>(ValidatePSK);
                _CoapServer.AddEndPoint(new CoAPEndPoint(_SecureChannel, CoapConfig.Default));
            }
            _CoapServer.Start();

            ServiceEventMessage message = new ServiceEventMessage();
            Imagination.Model.LWM2MServer lwm2mServer = new Imagination.Model.LWM2MServer();
            lwm2mServer.Url = ServiceConfiguration.ExternalUri.ToString();
            message.AddParameter("Server", lwm2mServer);
            BusinessLogicFactory.ServiceMessages.Publish("LWM2MServer.Start", message, TMessagePublishMode.Confirms);

            _ServerEndPoint = string.Concat("net.tcp://", ServiceConfiguration.Hostname, ":", port.ToString(), "/LWM2MServerService");
            if (_NativeServerAPI == null)
                _NativeServerAPI = new NativeIPCServer(AddressFamily.InterNetwork,port);
            _NativeServerAPI.Start();
            if (_NativeServerAPIv6 == null)
                _NativeServerAPIv6 = new NativeIPCServer(AddressFamily.InterNetworkV6, port);
            _NativeServerAPIv6.Start();
            //if (_ServiceHost != null)
            //    _ServiceHost.Close();
            //_ServiceHost = new ServiceHost(typeof(Imagination.Service.ServerAPI));
            //ServiceThrottlingBehavior throttle = _ServiceHost.Description.Behaviors.Find<ServiceThrottlingBehavior>();
            //if (throttle == null)
            //{
            //    throttle = new ServiceThrottlingBehavior
            //    {
            //        MaxConcurrentCalls = 100,
            //        MaxConcurrentSessions = 100,
            //        MaxConcurrentInstances = int.MaxValue
            //    };
            //    _ServiceHost.Description.Behaviors.Add(throttle);
            //}
            //else
            //{
            //    throttle.MaxConcurrentCalls = 100;
            //    throttle.MaxConcurrentSessions = 100;
            //    throttle.MaxConcurrentInstances = int.MaxValue;
            //}
            //NetTcpBinding netTcpBinding = new NetTcpBinding();
            //_ServiceHost.AddServiceEndpoint(typeof(Imagination.Service.ILWM2MServerService), netTcpBinding, _ServerEndPoint);
            ////int newLimit = _ServiceHost.IncrementManualFlowControlLimit(100);
            //_ServiceHost.Open();
        }
コード例 #37
0
ファイル: CoapClientTest.cs プロジェクト: rlusian1/CoAP.NET
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);
            _resource = new StorageResource(TARGET, CONTENT_1);
            _server = new CoapServer();
            _server.Add(_resource);

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }
コード例 #38
0
ファイル: ResourceTreeTest.cs プロジェクト: rlusian1/CoAP.NET
        private void CreateServer()
        {
            CoAPEndPoint endpoint = new CoAPEndPoint(0);

            _resource = new TestResource(NAME_1, PAYLOAD);
            _server = new CoapServer();
            _server
                .Add(new Resource(RES_A)
                    .Add(new Resource(RES_AA)
                        .Add(_resource
                            .Add(new TestResource(CHILD, CHILD_PAYLOAD)))));

            _server.AddEndPoint(endpoint);
            _server.Start();
            _serverPort = ((System.Net.IPEndPoint)endpoint.LocalEndPoint).Port;
        }