How to debug a simulated browser client of socket.

2019-03-05 11:02发布

问题:

I have simulated a browser client of socket.io in the node.js server

I am creating the simulated browser client when particular message arrived from a Real browser client.

     console.log('creating client of '+sessionId);
    var socket=client.init();

    console.log(socket);

here is my Simulated browser client in node.js , I am using https://github.com/saschagehlich/node-socket.io-client for creating client.

exports.init=function(){
    var socket = new io.Socket(config.host, {port: config.port, rememberTransport: false});
    // when connected, clear out display
    socket.on('connect',function() {
        console.log('dummy user connected');
    });
    socket.on('disconnect',function() {
        console.log('disconnected dummy');
    });
    socket.on('message', function(data){
      console.log(data);
    });
    socket.connect();
    return socket;
};

The problem is this that the consoles in the client is not getting printed , the socket is return and printed . but not console. in client code. And i also want the session id of simulated client , how can i get it ?

回答1:

Node.js has a simple debugger that can be invoked using:

node debug script.js

The debugger has simple commands like print or step. You could write code inline and use util.inspect() for inspecting objects.

Something more advanced would be using Google's V8 debugger http://code.google.com/p/v8/wiki/DebuggerProtocol but that's usually an overkill...