Comments (7)
The way observe currently works is a little wonky sometimes. AFAIK it does the following:
- when a request is received, we use coap-lite to intercept the request and handle observation in the crate directly
- updates to a resource are done "automatically" when you put / post to the same resource
- It may be the case that you get a 404 because observe currently "lazily" keeps track of existing resources only AFTER you interact with them. Please look at the tests under src/observer.rs if you want to see how it currently works (you need to send a PUT request first)
- also note that the current observe API can result in your futures not waking up properly if you continue to use the client after observing something (you will have 2 futures polling the same socket if you try to send requests after starting to observe something).
It is pretty difficult to get observe to work like it does in something like libcoap without reworking the server API to define Resources instead of a single handler function. Until then, please look at the tests for observer.rs and see if it works for your use-case
from coap-rs.
Many thanks. That explains the behaviour I'm seeing.
Perhaps consider this a feature request: To add a mechanism/option that allows the coap::Server's auto-observe handling to be disabled, in which case observe requests get passed to the handler instead of being internally handled.
For my use case, I could then take responsibility for managing the list of observers based on source IP:Port and token and also take responsibility for pushing notification packets as needed.
from coap-rs.
Currently the resource only can be observed after it was created by a PUT request. The resource is updated by sever automatically.
Do you want handle the observe by yourself?
from coap-rs.
I think so, yes.
For my scenario, I don't want to force the client to do a PUT before doing a GET+OBS.
Consequently, my program needs to detect the GET+OBS request, generate the resource if it doesn't yet exist, reply to the GET and insert/update the observer list.
I'm also considering a distributed approach, where my resources are stored externally (e.g. Redis). With this in mind, the GET/PUT/POST/DELETE operations when handled by the Server get read/written to Redis. I'd then have a separate process that manages the observer notifications.
from coap-rs.
Okey. I will add an option to enable observe message transparent transmission.
from coap-rs.
Brilliant. Many thanks.
from coap-rs.
The server has a new method: disable_observe_handling
. You can find the usage in test case spawn_server_disable_observe
.
from coap-rs.
Related Issues (20)
- Generic subject observer (RFC 7641) support HOT 5
- Server::run abruptly returns when a response payload is too large HOT 4
- Observe requests crash server if the client uses an empty vec![] to represent Observe: 0
- Migrate to Rust 2021 edition HOT 1
- Updating observes from server? HOT 10
- Crash when using python aiocoap HOT 2
- Unexpected panic due to network connectivity state HOT 1
- Outdated documentation refrenced HOT 1
- Message IDs and tokens not set HOT 2
- Client: Separate responses not processed HOT 2
- GET, POST etc. with Uri-Host HOT 2
- Blockwise transfer for with a request payload HOT 4
- Server response retransmission due to duplicate client request (duplicate MID) HOT 3
- Update coap-lite dependency HOT 2
- 0.12.2's update of coap-lite is incompatible HOT 1
- No easy way to set options in client requests HOT 8
- Mio 1.8.8 incompatible with newer Tokio versions HOT 3
- observe uses hard-coded default receive timeout HOT 1
- Inject/queue a notification for the Server to dispatch HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coap-rs.