首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coap.Net -启动

Coap.Net -启动
EN

Stack Overflow用户
提问于 2017-07-23 14:56:12
回答 1查看 1.3K关注 0票数 0

我目前正试图从CoAP in C#开始。我使用的库是CoAP.Net (→https://github.com/smeshlink/CoAP.NET)。

不幸的是,在“快速启动”-Section on GitHub中发布的示例中,我甚至没有成功。

我的服务器代码:

代码语言:javascript
复制
class Program
{
    static void Main(string[] args)
    {
        CoapServer server = new CoapServer();
        server.Add(new HelloWorldRessouce());
        server.Start();
    }
}

以及服务器解决方案中的重新源类:

代码语言:javascript
复制
class HelloWorldRessouce : CoAP.Server.Resources.Resource
{
    public HelloWorldRessouce() : base("hello-world")
    {
        Attributes.Title = "GET a friendly greeting!";
    }

    protected override void DoGet (CoapExchange exchange)
    {
        exchange.Respond("Hello World fron CoAP.NET!");
    }
}

在客户端,我得到了以下信息:

代码语言:javascript
复制
    static void Main(string[] args)
    {
        CoapClient client = new CoapClient();

        Request request = new Request(Method.GET);
        //request.URI = new Uri("coap://[::1]/hello-world");
        request.URI = new Uri("coap://192.168.178.48:5683/hello-world");
        request.Send();

        // wait for response
        Response response = request.WaitForResponse();
    }

以下是服务器的控制台输出:

调试启动CoAP服务器 调试- BlockwiseLayer使用MaxMessageSize: 1024和DefaultBlockSize:512 DBEUG -绑定到::ffff:0:0:5683的起始端点 按任何键..。

下面是客户机的控制台输出:控制台-输出-客户机

我很确定,问题在客户端.

如果有人能帮我运行这个例子,那就太棒了。或者,有人可以给我举几个例子。举个例子-档案帮不了我解决这个问题.

谢谢大家..。干杯,米尔科

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-24 08:34:27

好吧,好像有最蠢的用户在工作.^^

服务器端:

代码语言:javascript
复制
static void Main(string[] args)
{
    CoapServer server = new CoapServer();
    server.Add(new HelloWorldRessouce());
    server.Start();
}

在“server.Start()”之后,程序完成,服务器关闭。

然后添加一个"Console.ReadKey();“,一切都很好。

如果有人有任何关于配置的例子,尤其是关于配置的例子,他们仍然会受到赞赏。

谢谢大家;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45266488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档