I am looking to send image data in binary format from a C++ WebSockets server to the browser and then have the browser to interpret the data to display the image to the end user.
Here is my C++ code to read image and send data -
WebsocketClient& client = (WebsocketClient&) (*pClient);
WebsocketDataMessage response(EchoCommunication);
FILE *img = fopen("test_image.png", "rb");
fseek(img, 0, SEEK_END);
unsigned long filesize = ftell(img);
char *buffer = (char*)malloc(sizeof(char)*filesize);
rewind(img);
while (!feof(img)) {
fread(buffer, 1, sizeof(buffer), img);
response.SetArguments(buffer);
}
client.PushPacket(&response);
In Chrome Network tab I am able to see binary frames being received but having no luck in displaying image in browser. I have doubts if data being sent is valid.
Please let me know where am I going wrong.