我正在尝试连接到tomcat客户端创建的websocket。 我看到的是ws:// localhost:8080 / cs-webapp / ws但是当我尝试连接到它时,我收到302错误。其他问题/答案不适用:(
我使用以下命令获取我机器上的开放端口列表,以及我看到的与tomcat相关的内容:
sudo lsof -PiTCP -sTCP:LISTEN
java localhost:21179 (LISTEN)
java *:63862 (LISTEN)
java *:49190 (LISTEN)
java *:8080 (LISTEN)
java *:8009 (LISTEN)
java TCP localhost:8005 (LISTEN)
java TCP *:58083 (LISTEN)
有了上述信息,有没有办法确定哪个是websocket端口以及如何连接它?
我尝试过的代码片段是:
#!/usr/bin/env node
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
console.log('WebSocket Client Connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function() {
console.log('echo-protocol Connection Closed');
});
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log("Received: '" + message.utf8Data + "'");
}
});
});
//client.connect('ws://localhost:8080/cs-webapp/ws', 'echo-protocol');
client.connect('ws://localhost:63862', 'echo-protocol');
//client.connect('ws://localhost:8080/cs-webapp/ws', 'echo-protocol');