oatpp / oatpp-websocket

oatpp-websocket submodule.
https://oatpp.io/
Apache License 2.0
83 stars 32 forks source link

Stream of frames from server to client. #37

Open erobledo opened 2 years ago

erobledo commented 2 years ago

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 commented 2 years ago

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.

qcryptly commented 1 year ago

Bad news, even having access to the AsyncWebSocket object doing sendOneFrameAsync doesn't seem to actually execute. Theres more stuff you have to do that I'm trying to figure out myself. There really is no point to having websockets if the server can't initiate a connection.