oatpp-websocket icon indicating copy to clipboard operation
oatpp-websocket copied to clipboard

Stream of frames from server to client.

Open erobledo opened this issue 2 years ago • 2 comments

I am trying to implement a one-way websocket endpoint that sends a never-ending stream of frames from the server to the client as soon as the connection is open and as soon as new data is available from some other part of the application.

I have searched through the oatpp websocket examples, and I have not found anything similar. All the examples seem to assume that the client initiates the communication, and all the frames sent from the server to the client are in "response" to a client frame.

It seems that server-initiated frames are not supported with the current oatpp-websocket framework. It looks like what I would need is to provide my own implementation of Task::run() inside oatpp::websocket::ConnectionHandler::handleConnection:

https://github.com/oatpp/oatpp-websocket/blob/d95c8ee6262d5e8051099018983715ebf4873db5/src/oatpp-websocket/ConnectionHandler.cpp#L70

Is there any other way to achieve this? Or is this maybe a feature planned for the future?

erobledo avatar May 12 '22 10:05 erobledo

Another way to achieve this kind of one-way stream would be to use the asynchronous API, and have an external thread send tasks to the appropriate Executor or Processor; the one running the corresponding AsyncWebSocket::Listener coroutine, I guess.

These tasks would simply call AsyncWebSocket::sendOneFrameAsync. But for that they would need to have access to the internal AsyncWebSocket object, and I can not find a way to get access to it.

erobledo avatar May 18 '22 12:05 erobledo