Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire responding event for a request while transmitting a large post with block1 option. #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CoAP.Example/CoAP.Client/ExampleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ public static void Main(String[] args)
{
if (byEvent)
{
request.Responding += (Object sender, ResponseEventArgs e) =>
{
Response response = e.Response;
if (response != null)
{
//Console.WriteLine(Utils.ToString(response));
if (response.Block1 != null)
Console.WriteLine($"Responding Time (ms): {response.RTT},BLOCK1--> NUM:{response.Block1.NUM}, MORE:{response.Block1.M}, SZX:{response.Block1.SZX}");
if (response.Block2 != null)
Console.WriteLine($"Responding Time (ms): {response.RTT},BLOCK2--> NUM:{response.Block2.NUM}, MORE:{response.Block2.M}, SZX:{response.Block2.SZX}");
}
};
request.Respond += delegate(Object sender, ResponseEventArgs e)
{
Response response = e.Response;
Expand Down
20 changes: 17 additions & 3 deletions CoAP.Example/CoAP.Server/Resources/LargeResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ class LargeResource : Resource

static LargeResource()
{
payload = new StringBuilder()
payload = getDefaultPayload();
}

protected static string getDefaultPayload()
{
return new StringBuilder()
.Append("/-------------------------------------------------------------\\\r\n")
.Append("| RESOURCE BLOCK NO. 1 OF 8 |\r\n")
.Append("| [each line contains 64 bytes] |\r\n")
Expand Down Expand Up @@ -60,12 +65,21 @@ protected override void DoGet(CoapExchange exchange)

protected override void DoPost(CoAP.Server.Resources.CoapExchange exchange)
{
exchange.Respond(payload);
//exchange.Respond(payload);
payload = exchange.Request.PayloadString;
exchange.Respond(StatusCode.Changed);
}

protected override void DoPut(CoAP.Server.Resources.CoapExchange exchange)
{
exchange.Respond(payload);
//exchange.Respond(payload);
payload = exchange.Request.PayloadString;
exchange.Respond(StatusCode.Created);
}
protected override void DoDelete(CoapExchange exchange)
{
payload = getDefaultPayload();
exchange.Respond(StatusCode.Deleted);
}
}
}
3 changes: 3 additions & 0 deletions CoAP.NET/OSCOAP/SecureBlockwiseLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ public override void ReceiveResponse(INextLayer nextLayer, Exchange exchange, Re
nextBlock.Token = response.Token; // reuse same token
}

// notify blocking progress
exchange.Request.FireResponding(response);

exchange.CurrentRequest = nextBlock;
log.Debug(m => m($"ReceiveResponse: Block message to send: {nextBlock}"));
base.SendRequest(nextLayer, exchange, nextBlock);
Expand Down
5 changes: 4 additions & 1 deletion CoAP.NET/Stack/BlockwiseLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ public override void ReceiveResponse(INextLayer nextLayer, Exchange exchange, Re
}

nextBlock.RemoveOptions(OptionType.Observe);


// notify blocking progress
exchange.Request.FireResponding(response);

exchange.CurrentRequest = nextBlock;
base.SendRequest(nextLayer, exchange, nextBlock);
// do not deliver response
Expand Down