https://github.com/oatpp/oatpp-ssdp
Oat++ extension module to work with SSDP protocol.
https://github.com/oatpp/oatpp-ssdp
cpp oatpp ssdp
Last synced: 12 months ago
JSON representation
Oat++ extension module to work with SSDP protocol.
- Host: GitHub
- URL: https://github.com/oatpp/oatpp-ssdp
- Owner: oatpp
- License: apache-2.0
- Created: 2020-06-10T23:02:11.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-21T20:09:08.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T22:51:45.479Z (over 1 year ago)
- Topics: cpp, oatpp, ssdp
- Language: C++
- Homepage: https://oatpp.io/
- Size: 92.8 KB
- Stars: 2
- Watchers: 6
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oatpp-ssdp [](https://dev.azure.com/lganzzzo/lganzzzo/_build/latest?definitionId=28&branchName=master)
Oat++ extension module to work with SSDP (Simple Service Discovery Protocol) protocol.
πFind the complete example project using **oatpp-ssdp** module - [Example IoT Hue](https://github.com/oatpp/example-iot-hue-ssdp)π
More about Oat++:
- [Oat++ Website](https://oatpp.io/)
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)
## Build And Install
*Note: you need to install the main [oatpp](https://github.com/oatpp/oatpp) module first.*
- Clone this repository.
- In the root of the repository run:
```bash
mkdir build && cd build
cmake ..
make install
```
## API
### Declare Necessary Components
In the `AppComponent.hpp` file:
```cpp
#include "oatpp-ssdp/SimpleSsdpUdpStreamProvider.hpp"
#include "oatpp-ssdp/SsdpStreamHandler.hpp"
...
/**
* Create provider of SSDP-UDP packets stream.
*/
OATPP_CREATE_COMPONENT(std::shared_ptr, ssdpStreamProvider)("ssdp", [] {
return oatpp::ssdp::SimpleSsdpUdpStreamProvider::createShared();
}());
/**
* We can reuse the HttpRouter for SSDP since SSDP message is complient to HTTP1.1.
*/
OATPP_CREATE_COMPONENT(std::shared_ptr, ssdpRouter)("ssdp", [] {
return oatpp::web::server::HttpRouter::createShared();
}());
/**
* Create SsdpStreamHandler component which uses Router component to route requests.
* It looks like a normal ConnectionHandler but is specialized on SsdpStreams and returns something conceptually very different
*/
OATPP_CREATE_COMPONENT(std::shared_ptr, ssdpStreamHandler)("ssdp", [] {
OATPP_COMPONENT(std::shared_ptr, router, "ssdp"); // get Router component
return oatpp::ssdp::SsdpStreamHandler::createShared(router);
}());
```
### Run SSDP Server
In the `App.cpp` file:
```cpp
/* Get stream provider component */
OATPP_COMPONENT(std::shared_ptr, ssdpStreamProvider, "ssdp");
/* Get stream handler component */
OATPP_COMPONENT(std::shared_ptr, ssdpStreamHandler, "ssdp");
/* Create server which takes provided streams and passes them to stream handler */
oatpp::network::server::Server server(ssdpStreamProvider, ssdpStreamHandler);
/* Priny info about server port */
OATPP_LOGD("Server", "Running SSDP on port %s...", ssdpStreamProvider->getProperty("port").getData());
/* Run server */
server.run();
```
### Handle SSDP Messages
In the `Controller.hpp` file:
```cpp
/**
* Other devices that want to discover you send 'M-SEARCH *' SSDP packages.
* You have to answer with a corresponding packet on this discovery.
*/
ENDPOINT("M-SEARCH", "*", star) {
auto response = createResponse(Status::CODE_200, "" /* empty body */);
// TODO - add correct response headers.
return response;
}
```