Today I fixed streaming of messages without needing to alter websocket clients for the protongraph-provider.
Basically I altered things slightly in my main send call:
int WorkerClient::send_to_protongraph_worker(const char* buf, int len) {
if (ws == NULL) {
ws = WebSocket::from_url("ws://" + std::string(pw_server_addr) + ":" + std::to_string(pw_server_port));
if(!ws) {
printf("Failed to connect to protongraph worker\n");
// TODO: log error
return 0;
} else {
printf("Connected to protongraph worker\n");
}
}
// Wait for the connection to be established
while (ws->getReadyState() == WebSocket::CONNECTING) {
sleep(100);
}
// Add to the buffer
ws->send(buf);
// Set up send/receive I/O
ws->poll();
// Flush the buffer
ws->dispatch(handle_message);
delete ws;
ws = NULL;
return 0;
}
The trick was to remove a check on ws->getReadyState() != WebSocket::CLOSED and instead wait for getReadyState to not return state CONNECTING. That was basically the trick.
I also pulled out the setup of the WorkerClient initialisation to a bit closer to the root of the main function for the process.
With these changes I was able to achieve my objective of getting streaming working the way I wanted.