smeshlink / coap.net Goto Github PK
View Code? Open in Web Editor NEWA C# implementation of the CoAP protocol
Home Page: open.smeshlink.com/CoAP.NET/
License: Other
A C# implementation of the CoAP protocol
Home Page: open.smeshlink.com/CoAP.NET/
License: Other
Hello,
I have developed an android CoAP client application using Californium java, and the server side using CoAP.NET C#. And I have noticed that there are some places where the server responses never reach the client. I can see the correct request in the server and it replies, but the reply never reaches the client.
I can reproduce this easily by connecting the android smartphone client wifi to a hotspot created by another smartphone.
Is there someone which knows why this happen?
Best Regards,
Fábio Cardoso
Hi,
I am having problem in cancelling registered observe option, making use of this function MarkObserveCancel(), but i see multiple observe option is registered for the same resource in wireshark.
How do I cancel these individually based on tokens ?
edwin
I submitted this pull request a while ago. However, it seems that this hasn't been pushed out to nuget yet. Could you update the nuget package to a newer version?
On some OS, if we set up an dual channel server, with IPv4-mapped IPv6 addresses enabled, the call to Socket.ReceiveFromAsync(SocketAsyncEventArgs)
may fail and throw an ArgumentException
saying "Invalid AddressFamily".
The flow is like:
ReadBuffer.RemoteEndPoint
is null
, set to AddressFamily.InterNetworkV6
;EndReceive()
, if the received endpoint is IPv4-mapped, it will be changed to AddressFamily.InterNetwork
;Socket.ReceiveFromAsync()
again.In this case, an endpoint of AddressFamily.InterNetwork
will be passed into the socket, resulting in an ArgumentException
. And the 'BeginReceive' will be started again, leading to an infinite recursion loop.
This happens in a PC with Win7 Ult, but not in another one with Win7 Ult SP1. I am wondering if there is anything happens in the .NET framework or IPv6 stack.
Create new IPEndPoint
instead of changing the IP address of the original one.
Commit 49838af fixes this issue.
No backward compatibility problems are expected.
HI,
I am running project from CoAP.NET-master CoAP.NET40.2010 when i build the solution it shows no error. Looks like in image 1
After build the solution shows no error. I set CoAP.Server.NET40 project under examples as a startup project and run the solution.
I add some line of code in main method of Examples/CoAP.Client.NET40 project and run the project as a new instance when I debug the code return nothing in response
Request request1 = new Request(Method.GET);
request1.URI = new Uri("coap://localhost:5683/hello-world");
request1.SetPayload("Hello hi", MediaType.TextPlain);
Request reqRes = request1.Send();
// wait for one response
Response response1 = request1.WaitForResponse();
Please let me know what should i pass from the client side and how i will process request on the server side. I want to implement CON,NON, “/.well-known/core”,“Separate Response”,“Observable” option using this code and want to process the request on the server side.
Thanks
If IPv6 is not supported by the OS (i.e. WinXP without IPv6 protocol installed), a SocketException of SocketError.AddressFamilyNotSupported
will be thrown when starts a server.
Commit 1f33943 fixes this issue.
No backward compatibility problems are expected.
If you cannot upgrade to latest code, you can manually add a CoAPEndPoint
of an IPv4 address before starting the server.
CoapServer server = new CoapServer();
server.AddEndPoint(new CoAPEndPoint(new IPEndPoint(IPAddress.Any, 5683)));
Hello,
I did a very simple ressource :
class RejectedResource: Resource
{
public RejectedResource() : base("RejectedResource")
{
Attributes.Title = "RejectedResource";
}
protected override void DoGet(CoapExchange exchange)
{
exchange.Reject();
}
}
But when I try to request a GET on this resource, the server never generate a RST message...
Nothing is sent at all.
Thanks for your help.
HI,
When I send the request to server and process the request using below code working fine
protected override void DoGet(CoapExchange exchange)
{
// the request contains all the info you sent from your client
Request request = exchange.Request;
// get payload from the request
string payload = request.PayloadString;
// and respond it
exchange.Respond("Hello" + payload);
}
But when I call REST API for processing the request payload data which take some time for processing the request after process the request when i respond(exchange.Respond("Hello");) to client it returns null.
protected override void DoGet(CoapExchange exchange)
{
// the request contains all the info you sent from your client
Request request = exchange.Request;
// get payload from the request
string payload = request.PayloadString;
// process the payload data request using RESTAPI which takes some time in process
// and respond it
exchange.Respond("Hello" + payload);
}
Please let me know what is the issue?
Thanks
Shreyansh Jian
example:
class RootResource : Resource
{
public RootResource() : base(String.Empty)
{
Attributes.Title = "Home";
}
protected override void DoGet(CoapExchange exchange)
{
exchange.Respond("Welcome !");
}
}
but not work. help, thanks.
Hi,
Sorry, again I am still very new to this. I was wondering if the current Coap.NET implements any security features? It is a nice to use library that will be added bonus if it has good security features.
Also, is there any enhancement features that are in progress/coming up for this framework?
Thanks and regards,
ML
Is CoAP over TCP supported in CoAP.NET? If not, is it in the roadmap?
This is the link to the RFC:
https://tools.ietf.org/html/draft-ietf-core-coap-tcp-tls-08
It would be nice to specify the number of retries when a timeout is received instead of always using 4.
Hi,
wonderful work on this lib but I use CoAP.NET.Core and I saw an important memory leak on the lib.
Here is the code leaking :
protected override void DoGet(CoapExchange exchange)
{
exchange.Accept();
//Response res = Response.CreateResponse(exchange.Request, StatusCode.Valid);
//res.ContentType = (int)GetContentType();
//res.Payload = Serialize();
exchange.Respond("Toto");
}
My program starts with 12MB of RAM consumed and after 1000 requests we reached 21MB, 3000 27MB, 10000 57MB and it never decreased.
Have you any idea?
It would be nice to override the _sequenceTimeout in TokenLayer.cs. For long running block1 transfers, it timeouts after a minute.
public TokenLayer()
: this(CoapConstants.DefaultOverallTimeout)
{ }
For accessing my CoAP Server I need to use an Identity and Key.
How to I configure the Identity and Key for the Client?
Regards,
Stefan Stranger
In the server side,may I send a request after response.
I try that after
exchange.Respond(...)
Request request = Request.NewGet();
request.Destination = exchange.Request.Source;
exchange.Request.EndPoint.SendRequest(request);
it donot work
Hi,
I am very new to coap.net and I have some questions regarding observed resource. I am using coap.net framework and tried to call "time" resource on client's side and it works (using "OBSERVE").
However, I am still not very sure on how the subscription to this resource can be stopped explicitly on client's side (probably a RST response to clear observation or something?).
Could you provide some examples on how it can be done?
Thanks!
ML
Hi,
Please let me know how we can send the token to COAP server and how we can define message type (CON, NON, ACK, RST) when we send client request to COAP server.
Thanks
I'm constructing a CoapClient
with a custom config to disable re-transmits:
var config = new CoapConfig
{
MaxRetransmit = -1,
};
_client = new CoapClient(config);
However, messages are still re-transmitting the default 4 times. I'm using GetAsync
and PutAsync
to send messages.
If I explicitly construct a Get Request and set its MaxRetransmit
to -1 and send it using SendAsync
, then it behaves as expected and does not retransmit.
How can I implement CoAP in a WCF Service?
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
By default the Level in LogManager is LogLevel.All. I do not see where I can change that to increase the level past debug.
If the sever returns client error not found, the client should not continue to request the resource.
I was trying to perform a Get to ''.well-known/core" using multicast:
// new a GET request
Request request = new Request(Method.GET, false);
request.Source = new IPEndPoint(IPAddress.Parse("10.132.1.58"), 5683);
request.Multicast = true;
request.URI = new Uri("coap://224.0.1.187/.well-known/core");
request.Send();
// wait for one response
Response response = request.WaitForResponse();
Console.WriteLine(response.PayloadString);
This doesn't seem to work, as it seems that the packet is not sent from the source I specified. Intestead, it will be using another interface which is not connected to the IoT network.
As a workaround, I had to disable the other networks.
HI,
Thanks for your valuable response on my pre issues.
I want to configure COAP.Net protocol in WCF. is it possible to configure endpoint in WCF which supports COAP.Net protocol.
Thanks
Shreyansh
Hi,
Please let me know how i will provide the security in coap server. Is there any possible way to provide security. How to implement proxy between client and server.
Please share me any link or document for COAP which contains all the details about COAP .
Thanks
I was planning to run this library in windows mobile 6.1 with compact net framework 3.5, however I could not run in the mobile emulator , It requires libraries from compact .net Framework 4.0.
Does CoAP.NET supports .NET compact framework 3.5
Hi,
I want to receive multiple times response from single request.
From the client I will send a request to server after receiving this request i want to response client multiple times with single request. Is there any way to implement this feature using COAP.net.
Thanks
Shreyansh jain
Binaries are 4 months old. Can you please update.
Does this library allow for blockwise transfers as described here: http://www.google.com/url?q=http%3A%2F%2Ftools.ietf.org%2Fhtml%2Fdraft-ietf-core-block-08&sa=D&sntz=1&usg=AFQjCNGpPAnNm15802QG7Kgw_7iJ0BWuPw
Hi,
I was able to register my CoAP sensor resource successfully and I get this notification every 30 secs, now I want to display this notification on a windows application, so for every change in state of the resource I want my display field to be updated. How do I handle this ? I see the notifications on wireshark, my windows application should get these notifications. How do I approach this ?
Edwin
stop in EndReceive(Exception)?
I believe the Matcher class is incorrect marking responses as duplicates as only checking Token and Message ID.
But should also check the Observe option is different (to previous responses).
Hi,
I downloaded https://github.com/smeshlink/CoAP.NET. There are a number of resources in Example/Server CarelessResource, FibonacciResource, HelloWorldResource, ImageResource, LargeResource, MirrorResource, SeparateResource,StorageResource, TimeResource. I register these resources from main method. Now I want to call each resources from client. Please let me know what should I pass argument in Client for access each Resources? Is there any document for access these resources.
How we will implement the proxy in CoAP.Proxy.NET40?
Thanks
Shreyansh
I successfully created and communicated with the demo server, a COMPILED F# CoAP clients based on the examples as DISCOVER coap://localhost and GET coap://localhost/hello.
But when I try the exact same code using F# interactive (REPL), I get: "Status : 4.05 Method Not Allowed".
Also, I did the same test, but using a CoAP server in F# interactive with the same behavior.
I am looking for suggestions why this is happening and how is the best way to debug the problem.
Hi,
How we can expose coaps endpoint in .net.
Thanks
Shreyansh
Hi,
I've just found in class Message that getters for ProxyUri and ProxyScheme get option OptionType.Accept but set valid option.
Is that correct?
I was very surprised when I set option Accept and the Utlis.OptionsToString returned something in ProxyScheme.
Hi,
I am creating a resource and implement DoGet method of this resource. I have number of different Get request. Is it possible to create multiple DoGet method in single resource or using query string.
Please let me know how we will manage it. How we will manage query string in COAP.net?
Thanks
Shreyansh
##Good day!
I use you library for having comminication with sensortag by Coap protocol.
But I have a problem after long time observe.
I do this:
Request request = GetRequest(type);
request.AckTimeout = -1; //To make timeout unlimit
request.Respond += (s, e) => method(s, e, new Guid(guid));
request.MarkObserve();
So it work, but after 10-12 hours timeout is occured and observer didnt work. I should observe to resource again. Why do it happen?
My sensortag sleep one hour then wakeup, send data by coap to client and sleep again
I am using following code:
server.FindEndPoint(5683).ReceivingRequest += new EventHandler<MessageEventArgs>(ExampleServer_ReceivingRequest);
I am able to receive client request by this method and want to send a custom acknowledgement.
I am expecting acknowledgement in the client side by this method
client.Respond += new EventHandler(client_Respond);
Please suggest me, how do I execute above issue.
Is there any available documentation on logging? All the flags seem to be set off by default. I am confused as to how to activate them. Does app config need to be modified?
Thanks,
David
Do you have in your plans to port Scandium for implementing DTLS security? or is there any way to Use DTLS with CoAP.NET?
With Ikea Trådfri demanding the use of PSK, can someone point me in the right direction on how to use it with CoAP.NET?
Thanks! :)
My IP of my host is: 10.0.2.181
This function is throwing an exception: (UDPChannel.cs)
static IPAddress MapToIPv4(IPAddress address)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
return address;
Byte[] bytes = address.GetAddressBytes();
Int64 newAddress = (bytes[12] & 0xff) | (bytes[13] & 0xff) << 8 | (bytes[14] & 0xff) << 16 | (bytes[15] & 0xff) << 24;
return new IPAddress(newAddress);
}
The value for newAddress is being set to a negative number (I think because the last part of my IP is > 127. My fix was to change to:
static IPAddress MapToIPv4(IPAddress address)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
return address;
Byte[] bytes = address.GetAddressBytes();
Byte[] array = new Byte[4];
array[0] = bytes[12]; array[1] = bytes[13]; array[2] = bytes[14]; array[3] = bytes[15];
return new IPAddress(array);
}
It appears the exchange class uses the endpoint to create the key. When sending a message to broadcast/multicast address, the response is completely ignored. Matcher::ReceiveResponse can't find the key associate for the response.
Hi,
How we can provide the security in COAP.net DTLS based PSK,RPK and certificate security.
Thanks
There are not boundary checks in BlockwiseLayer.GetNextRequestBlock()
and BlockwiseLayer.GetNextResponseBlock()
. If a wrong block number arrives, the code may crash.
Check block range in GetNextResponseBlock()
.
Commit 4d8e0bf fixes this issue.
No backward compatibility problems are expected.
System.OverflowException
CoAP.Stack.BlockwiseLayer.GetNextResponseBlock(Response response, BlockwiseStatus status)
CoAP.Stack.BlockwiseLayer.SendResponse(INextLayer nextLayer, Exchange exchange, Response response)
Hi,
In your example, we are using Http request response classes in Client.
How can we use CoAP specific request and response as System.Net is used in Message class inherited by (Coap.Request class).
Thanks
Ankush
if we want to send data to server what are the parameters for CoAP.NET.Client ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.