socket.io-client-cpp icon indicating copy to clipboard operation
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?

Open Dschenker24 opened this issue 3 years ago • 2 comments

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?

Dschenker24 avatar Apr 14 '22 21:04 Dschenker24

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);

zeze-zeze avatar Aug 04 '22 09:08 zeze-zeze

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.

akhedr32 avatar Aug 18 '22 13:08 akhedr32