mardi 26 novembre 2019

Node js server and c++ client socket io connection , not able to emit or read the data

I cannot get this simple test work. I wrote the client in C++ and the server in NodeJS, both running on my computer. When I execute the client application, the console outputs this text...but the event 'key' is never fired on the server!

Client console output:

Error: No active session [2019-11-21 17:30:11] [connect] Successful connection [2019-11-21 17:30:11] [connect] WebSocket Connection 127.0.0.1:8081 v-2 "WebSocket++/0.8.1" /socket.io/?EIO=4&transport=websocket&t=1574353811 101

C++ client

#include "pch.h"
#include <iostream>

#include <sio_client.h>

using namespace sio;
using namespace std;

int main()
{
    sio::client io;
    io.connect("http://127.0.0.1:8081");

    string command = "w";

    io.socket()->emit("key", command );

}

NodeJS server

'use strict';

const express     = require('express');
const app         = express();
const serverHttp  = require('http').Server(app); 
const io = require('socket.io')(serverHttp);

const port = 9876;

io.on('connection', function (socket) {   
    // Never fired :(
    socket.on('key', function (data) {
        console.log("key received!!!");
    });
});

serverHttp.listen(port, function() {  
    console.log("init!!!");    
});

could you please fix this , i saw someone asking the same question in github issues section for socket io c++ client, no one has answered yet. please help out

if i am missing some codes in client please let me know . i just followed what they have mentioned in here. https://github.com/socketio/socket.io-client-cpp

Aucun commentaire:

Enregistrer un commentaire