gpt4 book ai didi

javascript - node.js net.connect() 尽管有 try-catch 错误

转载 作者:行者123 更新时间:2023-12-05 03:41:26 24 4
gpt4 key购买 nike

尽管有 try-catch block ,此代码仍会产生错误...如果服务器无法访问,它应该发送一条错误消息,如果可以,则应该发送一条肯定消息。

try {
net.connect(25565, "mc.hypixel.net", () => {
console.log("connected");
});
} catch (err) {
console.log("not connected");
}

这是错误:

events.js:292
throw er; // Unhandled 'error' event
^

Error: connect ETIMEDOUT 104.16.78.21:25565
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '104.16.78.21',
port: 25565
}

谢谢你的帮助:)

最佳答案

嗯..我相信下面的答案是什么net建议

试试这个

net.connect(25565, "mc.hypixel.net", () => {
console.log("connected");
})
.on('error', (err)=>console.log("not connected"));

关于javascript - node.js net.connect() 尽管有 try-catch 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67790720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com