Can i create a dummy socket.io client inside the s

2019-07-23 21:19发布

We are writing an Application- which need a dummy user as a socket.io client with the user ,which will act as a dummy user , to send and recieve messages . Each user will have the dummy client that should be able to send message to client(User).

I need help for implementing this.

This is my server connection handler .I want to create a socket.io client here , as new client is connected on server .Can i develope it if yes then how ?

   self.socket.on('connection', function(client){
      //here i want to create a seperate module for handling dummy users 
      // for sending and recieving message.

    }); 

How will i include Socket.io Client Script in node ? updating the client i write on server

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

Here i am creating the client

if (message._command=='login') {
        console.log('creating client of '+sessionId);
        var socket=client.init();

        console.log(socket);
    }

This console is printed .

1条回答
Root(大扎)
2楼-- · 2019-07-23 21:52

We are writing an Application- which need a dummy user as a socket.io client with the user ,which will act as a dummy user , to send and recieve messages.

If you want to simulate browser clients through the server which are connected to your socket.io server you can try to use some of the node.js socket.io clients, such as node-socket.io-client or Socket.IO-node-client.

查看更多
登录 后发表回答