【问题标题】:Not emit data socket.io c++ (Client) to socket.io nodejs (Server)不向socket.io nodejs(服务器)发出数据socket.io c++(客户端)
【发布时间】:2019-03-15 02:03:06
【问题描述】:

对于我的项目,我想通过 Socket.io 从 App (c++) 到 WebServer (NodejS) 进行通信。

我们之间的联系有效,但是当我发出一条消息时,什么都没有发生 ...

客户端 (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;
  ...
}

服务器(NodeJ)

...
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`);
})

客户端输出

[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

服务器输出

控制台显示“新连接...”

对于客户,我使用这个: https://github.com/socketio/socket.io-client-cpp

对于服务器:socket.io@2.1.1

有人有解决办法吗?

谢谢!

【问题讨论】:

    标签: c++ node.js boost websocket socket.io


    【解决方案1】:

    像这样发射:

    string someString = "hi there";
    message::list someStringMessage(someString);
    io.socket()->emit("newString", someStringMessage);
    

    【讨论】:

      猜你喜欢
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 2017-07-25
      • 2021-01-26
      相关资源
      最近更新 更多