socket.io-client-cpp
socket.io-client-cpp copied to clipboard
How to send an array of floating point values from socket.io c++ client to socket.io nodejs server?
I have a socket.io nodejs server and socket.io c++ client already set up. I am able to emit simple string message events and receive the data on my server side. However, my end goal is to send an array of floating point values (to be graphed on server side) from the client to the server. I am not very familiar with C++ and the syntax for creating an array_message object is confusing me. Could anyone elaborate on how I might go about creating an array_message object with randomly generated floating point values?
You can use message::list to do the job.
For example, we need to send int and string message.
sio::message::list task;
task.push(sio::int_message::create(1));
task.push(sio::string_message::create(std::string("string message")));
socket->emit("event", task);
char buffer[DATASIZE* sizeof(float)];
memcpy(&buffer[0], fData ,DATASIZE * sizeof(float));
socket->emit(eventName, std::make_shared<std::string>((char*)buffer,DATASIZE* sizeof(float)));
this will send binary data through socket.