English 中文(简体)
node.js Websocket 服务器到 html
原标题:node.js websocket server to html

我在想你能不能帮我个忙,我刚来过结点Js, 希望能帮上点忙。

我有一个简单的 html (客户端) 页面, 使用 jquery 和 socket. io. js 外部服务器。 客户端将事件发送到用作 Websocket 服务器的节点 js 应用程序, 这个功能和预期效果都很好 。

然而我却不知道该如何用比主控台.log(在节点.js app中)更有用的东西来写反响事件。

此时此刻,情况再简单不过了。

var io = require( socket.io ).listen(8000);

io.set( log level ,1);

io.sockets.on( connection , function (socket) {  
    socket.on( clientevent , function (message) {
        console.log(message);
    });
    socket.on( disconnect , function () {
        console.log( disconnected );
    });
});

我希望能够将事件从客户端. html 写入到 html 的某个 html (DOM) 中, 从 node. js app. 我想用jquery s $ (# event). append( message) 等东西来做这件事, 还可以通过 $ (# poorid) 之类的东西与节点. js 服务器交谈 。 单击...

还是我完全搞错了?

最佳回答

基本的例子非常完美 。 < a href="https://gist.github.com/2814934" rel=“nofollow” >Socket.io example with Jquery and DOM management 使您有一个使用 Jquery 和 DOM 操作的更详尽的例子。 您需要将客户端. html 上传到网络服务器, 从节点运行 ap.js 然后访问客户端. html 。

Socket.io 在 8000 端口监听, 客户已被配置到该端口访问它。 具体提及 < a href=" https:// gist.github.com/ 2814934# L44" rel = “ nofollow” > DOM 操作 的代码, 使用 Jquery 。

希望这能帮上忙

问题回答

暂无回答




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签