smeshlink / CoAP.NET

A C# implementation of the CoAP protocol
open.smeshlink.com/CoAP.NET/
Other
159 stars 81 forks source link

CoAP Blockwise transfer #41

Open SachinEdwin opened 8 years ago

SachinEdwin commented 8 years ago

Hi, I am new to this CoAP project and i am making using use of coap.net. Working on blockwise transfer in order to GET payload of 100 bytes. How do I start with this? I read the latest RFC on blockwise transfer where it says make use of blockoption 2 for GET method. Any way to approach this / sample code / pointers would be appreciated

Best Regards, Sachin Edwin

longshine commented 8 years ago

Hi~

You don't have to specify a Block2 option. In this case the size of blocks will be negotiated between the client and server. The lib will decide automatically whether a blockwise transfer is needed according to the size of payload.

If you prefer any other size of one block, you may specify a Block2 option before sending the request:

  /*
   * In this case, the 2nd param (num) must be 0;
   * the 3rd param (szx) stands for the block size:
   *   block size = 1 << (szx + 4)
   * 1 for 32 bytes per block
   * It must between 0 and 6.
   */
  request.SetOption(new BlockOption(OptionType.Block2, 0, 1, false));

You may try the CoAP.Example/CoAP.Client example to get the '/large' resource in the CoAP.Example/CoAP.Server example to see the result.

SachinEdwin commented 8 years ago

Hi,

Thanks for your reply. I am using a stack from openwsn , the above block option is independent of which stack I use? blockoption is not implemented in openwsn stack (server side), so will this work?

longshine commented 8 years ago

Sorry that this feature will not work without support on the server side.

janaki2 commented 7 years ago

Hi,

I have a question on SZX in the Block2 Option.

Does the payload bytes of the response packet MUST be exactly same as the SZX chosen in Block2 Option or Can it differ with that of SZX?

For example, I send a Block which is NOT the last block and I choose SZX = 2 (i.e., Block size is 64 bytes). But the actual payload in the response is 75 bytes or 57 bytes not 64 bytes. Is this valid?

Thanks!