简体   繁体   中英

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

I have this sample websocket server in nodejs test-websocket-server

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:

$ java -jar tyrus-client-cli-1.1.jar ws://localhost:8080/mypath Connecting to 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)

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 / :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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