我有一个使用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)
})
套接字永远不会被记录;谁能帮我?谢谢