我如何做多个Dnode连接?

我正在做一个自动完成input表单,我想发送我的用户types到远程数据库的build议。

我现在使用dnode,而且我不想在每次我的用户input时都做一个新的远程连接,所以我把远程function全局化了

dnode.connect(5050, function (remote) { window.remote = remote }); 

所以每次我想检查我的mongodb我只是使用window.remote.function而不必重新连接。 有更好的方法吗?

谢谢

将自动完成侦听器绑定在dnode连接的范围内,而不是将连接暴露给外部。

而不是做:

 dnode.connect(5050, function (remote) { window.remote = remote }); autoCompleteLogic(window.remote) 

做这个,而不是:

 dnode.connect(5050, function (remote) { autoCompleteLogic(remote) }); 

我build议直接使用Socket.IO来实现这一点,DNode实际上是用来在服务器和浏览器之间交换信息的。 在以下网站上查找有关Socket.io的更多信息: