• 大小: 1023KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-30
  • 语言: 其他
  • 标签: coap  

资源简介

物联网COAP协议的CSharp实现,VS2010

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EXILANT.Labs.CoAP.Channels;
using EXILANT.Labs.CoAP.Exceptions;
using EXILANT.Labs.CoAP.Message;
using EXILANT.Labs.CoAP.Helpers;
using System.Collections;
using System.Threading;

namespace CoapServer {
    class Program {

        /// 
        /// Holds the instance of the server channel class
        /// 

        private CoAPServerChannel _coapServer = null;

        static void Main(string[] args) {
            Program p = new Program();
            p.StartServer();
            Thread.Sleep(Timeout.Infinite);//block here
        }
        /// 
        /// Start the server
        /// 

        public void StartServer() {
            this._coapServer = new CoAPServerChannel();
            this._coapServer.Initialize(null 5683);//Initialize and listen on default CoAP port
            //Setup event listeners
            this._coapServer.CoAPRequestReceived += new CoAPRequestReceivedHandler(OnCoAPRequestReceived);
            this._coapServer.CoAPResponseReceived += new CoAPResponseReceivedHandler(OnCoAPResponseReceived);
            this._coapServer.CoAPError += new CoAPErrorHandler(OnCoAPError);
        }
        private int GetRoomTemperature() {
            int temp = DateTime.Now.Second;
            if (temp < 15)
                temp = 25;// just do not want to show that it‘s too cold!
            return temp;
        }
        void OnCoAPResponseReceived(CoAPResponse coapResp) { }
        void OnCoAPError(Exception e AbstractCoAPMessage associatedMsg) { }

        void OnCoAPRequestReceived(CoAPRequest coapReq) {
            //This sample only works on NON requests of type GET
            //This sample simualtes a temperature sensor at the path “sensors/temp“

            string reqURIPath = (coapReq.GetPath() != null) ? coapReq.GetPath().ToLower() : ““;
            /**
                * Draft 18 of the specification section 5.2.3 states that if against a NON message
                * a response is required then it must be sent as a NON message
                */
            if (coapReq.MessageType.Value != CoAPMessageType.NON) {
                //only NON  combination supported..we do not understand this send a RST back
                CoAPResponse msgTypeNotSupported = new CoAPResponse(CoAPMessageType.RST /*Message type*/
                                                                    CoAPMessageCode.NOT_IMPLEMENTED /*Not implemented*/
                                                                    coapReq.ID.Value /*copy message Id*/);
                msgTypeNotSupported.Token = coapReq.Token; //Always match the request/response token
                msgTypeNotSupported.RemoteSender = coapReq.RemoteSender;
                //send response to client
                this._coapServer.Send(msgTypeNotSupported);
            } else if (co

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        144  2014-04-23 22:26  0.3.0\CoapServer\app.config

     文件      66048  2014-04-23 22:35  0.3.0\CoapServer\bin\Debug\ClassLibrary1.dll

     文件     194048  2014-04-23 22:35  0.3.0\CoapServer\bin\Debug\ClassLibrary1.pdb

     文件       6656  2014-04-23 22:35  0.3.0\CoapServer\bin\Debug\CoapServer.exe

     文件        144  2014-04-23 22:26  0.3.0\CoapServer\bin\Debug\CoapServer.exe.config

     文件      15872  2014-04-23 22:35  0.3.0\CoapServer\bin\Debug\CoapServer.pdb

     文件      11600  2014-04-23 22:38  0.3.0\CoapServer\bin\Debug\CoapServer.vshost.exe

     文件        144  2014-04-23 22:26  0.3.0\CoapServer\bin\Debug\CoapServer.vshost.exe.config

     文件        490  2010-03-17 22:39  0.3.0\CoapServer\bin\Debug\CoapServer.vshost.exe.manifest

     文件       2738  2014-04-23 22:26  0.3.0\CoapServer\CoapServer.csproj

     文件        634  2014-04-23 22:38  0.3.0\CoapServer\obj\x86\Debug\CoapServer.csproj.FileListAbsolute.txt

     文件       5670  2014-04-23 22:35  0.3.0\CoapServer\obj\x86\Debug\CoapServer.csprojResolveAssemblyReference.cache

     文件       6656  2014-04-23 22:35  0.3.0\CoapServer\obj\x86\Debug\CoapServer.exe

     文件      15872  2014-04-23 22:35  0.3.0\CoapServer\obj\x86\Debug\CoapServer.pdb

     文件       5847  2014-04-28 09:49  0.3.0\CoapServer\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       5840  2014-04-23 22:31  0.3.0\CoapServer\Program.cs

     文件       1352  2014-04-23 22:25  0.3.0\CoapServer\Properties\AssemblyInfo.cs

    ..A..H.    146944  2014-03-31 15:26  0.3.0\coapsharp.suo

     文件      64512  2014-04-22 10:51  0.3.0\ConsoleApplication1\bin\Debug\coapsharp.dll

     文件     192000  2014-04-22 10:51  0.3.0\ConsoleApplication1\bin\Debug\coapsharp.pdb

     文件     128012  2014-04-22 10:51  0.3.0\ConsoleApplication1\bin\Debug\coapsharp.xml

     文件       4608  2014-04-22 10:51  0.3.0\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe

     文件      11776  2014-04-22 10:51  0.3.0\ConsoleApplication1\bin\Debug\ConsoleApplication1.pdb

     文件       2690  2014-04-22 17:01  0.3.0\ConsoleApplication1\ConsoleApplication1.csproj

     文件          0  2014-04-22 10:52  0.3.0\ConsoleApplication1\obj\x86\Debug\build.force

     文件        735  2014-04-22 10:51  0.3.0\ConsoleApplication1\obj\x86\Debug\ConsoleApplication1.csproj.FileListAbsolute.txt

     文件      10391  2014-04-22 10:51  0.3.0\ConsoleApplication1\obj\x86\Debug\ConsoleApplication1.csprojResolveAssemblyReference.cache

     文件       4608  2014-04-22 10:51  0.3.0\ConsoleApplication1\obj\x86\Debug\ConsoleApplication1.exe

     文件      11776  2014-04-22 10:51  0.3.0\ConsoleApplication1\obj\x86\Debug\ConsoleApplication1.pdb

     文件       5975  2014-04-22 10:53  0.3.0\ConsoleApplication1\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

............此处省略223个文件信息

评论

共有 条评论