【发布时间】:2018-05-10 12:49:39
【问题描述】:
我正在尝试了解 WebSocket 在 Node.js 中的工作方式,但在发送消息时遇到了一些问题。
我的 WebSocket 服务器配置如下 (index.js)
var ws = require("ws");
var wsserver = new ws.Server ({
server: httpserver,
port: 3030
});
wsserver.on (
"connection", function connection(connection) {
console.log("connection");
}
);
wsserver.on (
"open", function open(open) {
console.log("open");
}
);
wsserver.on (
"message", function message(message) {
console.log("message");
}
);
这似乎工作正常,因为我可以使用建立连接
var wscon = new WebSocket("ws://192.168.20.88:3030");
然后给我服务器上的连接输出。如果我尝试使用发送,但似乎什么也没发生,也没有错误消息
wscon.onopen = function(open) {
wscon.send("test message");
}
我一定错过了什么,但我不知道是什么
【问题讨论】:
标签: node.js websocket messaging