简体   繁体   English

为什么Node.js中的示例Websocket项目卡在“连接”中? 提供的例子

[英]Why sample websocket project in nodejs stuck in “Connecting”? example provided

I have this sample websocket server in nodejs test-websocket-server 我在nodejs test-websocket-server中有这个示例websocket 服务器

When I run it it "appears" to have started up. 当我运行它时,它“似乎”已经启动。

but when I try using tyrus (or any other means) websocket client to connect to it i'm stuck in connecting phase: 但是当我尝试使用tyrus (或任何其他方式)websocket客户端连接到它时,我陷入了连接阶段:

$ java -jar tyrus-client-cli-1.1.jar ws://localhost:8080/mypath Connecting to ws://localhost:8080/mypath... $ java -jar tyrus-client-cli-1.1.jar ws:// localhost:8080 / mypath连接到ws:// localhost:8080 / mypath ...

it just stays like this in "connecting" phase from what I understand it should get "connected". 据我了解,它应该保持“连接”状态,只是停留在“连接”阶段。

source of the app.js (which also appears in link to github) app.js源代码(也出现在github的链接中)

var wsServer = require('ws').Server;
var ws = new wsServer({
  port: '8080',
  path: 'mypath'
});

ws.on('open', function open() {
  ws.send('something');
});

ws.on('message', function(data, flags) {
  console.log("got message: " + data)
  // flags.binary will be set if a binary data is received.
  // flags.masked will be set if the data was masked.
});

As per RFC 6455 , you need to prefix the path with a / : 根据RFC 6455 ,您需要在路径前面加上/

var wss = new wsServer({
  port: 8080,
  path: '/mypath'
});

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

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