简体   繁体   中英

DNode implementation for websocket communication in node.js

I don't understand the way DNode uses websocket communication. Some say it uses socket.io others say sockjs . Which one is it? Or is it possible to choose?

I'm trying to use DNode, but I also need access to the connections for (semi-)broadcasting in reaction to RPC calls. How do I do this?

Is there a more extensive manual on dnode somewhere?

Your question is kind of vague. I'm not exactly sure whether DNode uses socket.io or sockjs, not sure it even uses one of those based on their dependencies list, but that is not really important when you program it.

As for using connections with DNode, it is pretty straight forward. Here's an example:

var server = dnode({
    pushMessageNotification: function(message, cb) {
        contact = getClientFromId(message.receiver);
        contact.socket.emit('messageNotification', {
            message: message.message,
            sender: message.sender,
            time: message.time
        });
        cb('success');
    }
});

So as you can see, pushMessageNotification is a method that I binded with DNode-PHP and the message is encoded in JSON through PHP. Afterward, all you need is a method to find the socket of the client based on its id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM