68 lines
1.1 KiB
Markdown
68 lines
1.1 KiB
Markdown
Web Socket Protocol Draft
|
|
==========================
|
|
|
|
Requirements:
|
|
- fast when necessary (not even msgpack overhead)
|
|
- sending live data updates
|
|
- easy otherwise, based on msgpack
|
|
- sending existing measured data
|
|
-
|
|
|
|
|
|
Message Format
|
|
--------------
|
|
|
|
- 1byte "opcode" (if lower than threshold, probably 8, pure binary msg, otherwise msgpack)
|
|
- msgpack data, or custom binary data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
class WebsocketConnection
|
|
{
|
|
sendMessage(opcode, optionalData); // optional data is packed via msgpck
|
|
registerMessageReceive(func, singleShot);
|
|
|
|
request(opcode, data, onReplyFunc); // with futures, async
|
|
// register a single shot receive that calls the "onReplyFunc", or promise
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
```cpp
|
|
|
|
class WebsocketInterface
|
|
{
|
|
public:
|
|
virtual bool onMessageReceived(websockets::WebsocketsClient &client)
|
|
{
|
|
|
|
}
|
|
|
|
protected:
|
|
WebsocketServer * server_;
|
|
}
|
|
|
|
class SessionWebsocketInterface
|
|
{
|
|
public:
|
|
|
|
}
|
|
|
|
|
|
class WebsocketServer
|
|
{
|
|
void sendToAll(char * data, size_t size);
|
|
|
|
void registerInterface(WebsocketInterface *);
|
|
};
|
|
|
|
```
|
|
|
|
can this be done with static polymorphism as well? does std::tuple and std::apply work?! -> test |