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.
You can review all of the source code for CoAP.NET on github.
I'm not familiar with this library, but from just a quick review, it looks like the DefaultBlockSize
configuration property is only referenced by CoapServer
(not CoapClient
).
Further evidence is in the BlockTransferTest fixture, which configures the CoapServer
with a particular block size on line 43.
You might also check line 161 of that same test class. It seems like you may be able to provide configuration settings for the endpoint as well.