Search code examples
c#coap

Coap.Net - Starting


I'm currently trying to start with CoAP in C#. The library I'm using is CoAP.Net (→ https://github.com/smeshlink/CoAP.NET).

Unfortunately, I didn't even succeed with the example published in the "Quick Start"-Section on GitHub.

My Server Code:

class Program
{
    static void Main(string[] args)
    {
        CoapServer server = new CoapServer();
        server.Add(new HelloWorldRessouce());
        server.Start();
    }
}

and a ressource-class in the Server solution:

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!");
    }
}

On the client-side I've got the following:

    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();
    }

Here is the Console-Output from the Server:

DEBUG - Starting CoAP server

DEBUG - BlockwiseLayer uses MaxMessageSize: 1024 and DefaultBlockSize:512

DBEUG - Starting endpoint bound to [::ffff:0:0]:5683

Press any key...

Here is the Console-Output from the Client: Console-Output - Client

I'm pretty sure, the problems are on the Client-side...

It would be awesome, if there's someone to help me get this example running. Or maybe, someone can give me a few Noob-Examples. The example-files don't really help me with this problem...

Thanks everybody... Cheers, Mirco


Solution

  • Okay, it seems as if there was the dumbest user at work...^^

    Server-side:

    static void Main(string[] args)
    {
        CoapServer server = new CoapServer();
        server.Add(new HelloWorldRessouce());
        server.Start();
    }
    

    after "server.Start();" the program is finished and the server turns off.

    By adding a "Console.ReadKey();" afterwards, everything is fine.

    If someone has any noob-examples espacially about the configuration, they are still appreciated.

    Thanks everybody ;)