简体   繁体   English

Node.js中用于Websocket通信的DNode实现

[英]DNode implementation for websocket communication in node.js

I don't understand the way DNode uses websocket communication. 我不了解DNode使用WebSocket通信的方式。 Some say it uses socket.io others say sockjs . 有人说它使用socket.io,有人说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. 我正在尝试使用DNode,但为了响应RPC调用,我还需要访问连接以进行(半)广播。 How do I do this? 我该怎么做呢?

Is there a more extensive manual on dnode somewhere? 在某处有关dnode的手册是否更详尽?

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. 我不确定DNode是否使用socket.io或sockjs,也不确定它甚至基于其依赖项列表使用其中之一,但这在编程时并不十分重要。

As for using connections with DNode, it is pretty straight forward. 至于将连接与DNode一起使用,这很简单。 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. 如您所见,pushMessageNotification是我与DNode-PHP绑定的一种方法,该消息通过PHP以JSON编码。 Afterward, all you need is a method to find the socket of the client based on its id. 之后,您所需要做的就是根据客户端ID查找客户端套接字的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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