Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not emit data socket.io c++ (Client) to socket.io nodejs (Server)

For my project, I would like to communicate with Socket.io from an App (c++) to a WebServer (NodejS).

The connexion between us works, but when I emit a message, nothing is happening ...

Client (C++)

int main(int argc, char const *argv[])
{
  sio::client h;
  h.connect("http://x.x.x.x:xxxx");
  string mess = "Bonjour !!!";
  h.socket()->emit("new message", mess); // Nothing is happening
  cout << "Message sended ..." << mess << endl;
  ...
}

Server (NodeJs)

...
const io = require('socket.io')(server);

io.on('connection', (socket) => {
  console.log("New connexion..."); // It's Work

  socket.on('new message', function (data) { 
    console.log(data); // Never fire
  });
});


server.listen(xxxx, () => {
    console.log(`Server started on port xxxx`);
})

Client output

[2018-10-10 07:30:49] [connect] Successful connection
[2018-10-10 07:30:49] [connect] WebSocket Connection x.x.x.x:xxxx v-2 "WebSocket++/0.8.1" /socket.io/?EIO=4&transport=websocket&t=1539156649 101
Message sended ...Bonjour !!!
[2018-10-10 07:30:49] [warning] got non-close frame while closing
[2018-10-10 07:30:49] [warning] got non-close frame while closing
sio closed

Server output

Console show "New connexion..."

For the Client, I use this : https://github.com/socketio/socket.io-client-cpp

For the Server : [email protected]

Does a person have a solution?

Thanks !

like image 570
Thomas Morvan Avatar asked Nov 08 '22 01:11

Thomas Morvan


1 Answers

Emit like this:

string someString = "hi there";
message::list someStringMessage(someString);
io.socket()->emit("newString", someStringMessage);
like image 168
lastpeony4 Avatar answered Nov 15 '22 05:11

lastpeony4