We are writing an application which needs a dummy user as a socket.io client with the user, which will act as a dummy user to send and receive messages. Each user will have the dummy client that should be able to send message to client (User).
This is my server connection handler. I want to create a socket.io client here, as new client is connected on server. How can I develop this?
self.socket.on('connection', function(client){
//here I want to create a separate module for handling dummy users
// for sending and receiving message.
});
How will I include Socket.io Client Script in node? Updating the client I write on server.
开发者_Go百科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.
We are writing an application which needs a dummy user as a socket.io client with the user, which will act as a dummy user to send and receive 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.
精彩评论