1

I'm a bit of a beginner in C# but what I'm coding a CoAP client that will test the throughput and response time of several CoAP servers at once. FYI the application is implemented as a command line program. The library I'm using is CoAP.NET.

Everything went just fine until I wanted to change the default block size from 512 bytes to something less like 32 bytes.

This is where my understanding of C# fails me, the settings are located in the interface ICoapConfig and the class CoapConfig. These settings just magically loads at some point.

I have tried to do this:

CoapConfig conf = new CoapConfig();
conf.DefaultBlockSize = 32;
CoapClient client = new CoapClient(conf);
...
Request req = new Request(Method.PUT);
req.SetPayload(payload, MediaType.TextPlain);
client.Send(req);

However the blocksize is still 512 as messages only get transferred blockwise when over 512b.

DEBUG - BlockwiseLayer uses MaxMessageSize: 1024 and DefaultBlockSize:512

This is the first line of output I get when running the program.

Happy for any help :)

SOLUTION:

CoapConfig conf = new CoapConfig();
conf.DefaultBlockSize = 32;
...
Request req = new Request(Method.PUT);
req.SetPayload(payload, MediaType.TextPlain);
req.URI = client.Uri;

IEndPoint _clientEndpoint;
_clientEndpoint = new CoAPEndPoint(conf);
_clientEndpoint.Start();
req.Send(_clientEndpoint);
...

I don't really know what this EndPoint thing might be but this lets you use a desired configuration when sending. FYI: I tried to set the config for the server to but with no success.

4

1 回答 1

0

您可以在 github 上查看CoAP.NET的所有源代码。

我不熟悉这个库,但从快速回顾来看,DefaultBlockSize配置属性似乎只被CoapServer(not CoapClient) 引用。

进一步的证据在BlockTransferTest夹具中,它在第 43 行CoapServer配置了特定的块大小。

您还可以检查同一测试类的第 161 行。您似乎也可以为端点提供配置设置。

于 2015-03-26T19:21:13.367 回答