WebSocket与“ wss:// url:port /”的连接失败:建立连接错误:net :: ERR_CONNECTION_TIMED_OUT

时间:2019-05-11 12:44:17

标签: javascript node.js http express ws

我有一个使用ws软件包的小型网络套接字。 但是,当我想从客户端连接到它时,出现此错误:

WebSocket connection to 'wss://url:port/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

另外,我放了一个socket.onerror = socket.onclose = function(e) { console.log(e) },它返回了:

bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: WebSocket {url: "wss://url:port/", readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
defaultPrevented: false
eventPhase: 0
isTrusted: true
path: []
returnValue: true
srcElement: WebSocket {url: "wss://url:port/", readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
target: WebSocket {url: "wss://url:port/", readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
timeStamp: 3908639.545000002
type: "error"
__proto__: Event
bubbles: false
cancelBubble: false
cancelable: false
code: 1006
composed: false
currentTarget: WebSocket {url: "wss://url:port/", readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
defaultPrevented: false
eventPhase: 0
isTrusted: true
path: []
reason: ""
returnValue: true
srcElement: WebSocket {url: "wss://url:port/", readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
target: WebSocket {url: "wss://url:port/", readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
timeStamp: 3908639.9450000008
type: "close"
wasClean: false
__proto__: CloseEvent

这是服务器端:

const express = require("express")
const app = express()
const server = require("http").Server(app)
const ws = require("ws")

const wss = new ws("wss://url:port")

wss.on("open", socket => console.log(socket))

app.use(express.static("public"));

app.get("/", function(request, response) {
  response.sendFile(__dirname + "/views/index.html")
})

server.listen(process.env.PORT, function() {
  console.log("Your app is listening on port " + server.address().port)
})

套接字永远不会被记录;谁能帮我?谢谢

0 个答案:

没有答案