我正在尝试在服务器端 NodeJS 上运行 Signalr 客户端。但我收到以下错误。我该如何解决这个问题?
Chat.js 代码
const signalR = require("@microsoft/signalr");
const connection = new signalR.HubConnectionBuilder()
.withUrl("http://127.0.0.1:7265/chathub")
.configureLogging(signalR.LogLevel.Information)
.build();
const start = async () => {
try {
await connection.start();
console.log("Connected to signal r hub");
} catch (error) {
console.log(error);
}
};
// starting the app
const startApp = async () => {
await start(); // connection will stablised
};
startApp();
我收到错误消息
[2023-04-08T07:27:03.490Z] Error: Failed to complete negotiation with the server: FetchError: request to http://127.0.0.1:7265/chathub/negotiate?negotiateVersion=1 failed, reason: connect ECONNREFUSED 127.0.0.1:7265
[2023-04-08T07:27:03.490Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: FetchError: request to http://127.0.0.1:7265/chathub/negotiate?negotiateVersion=1 failed, reason: connect ECONNREFUSED 127.0.0.1:7265
FailedToNegotiateWithServerError: Failed to complete negotiation with the server: FetchError: request to http://127.0.0.1:7265/chathub/negotiate?negotiateVersion=1 failed, reason: connect ECONNREFUSED 127.0.0.1:7265
at HttpConnection._getNegotiationResponse (/Users/user/Desktop/WebChat-Client-master/node_modules/@microsoft/signalr/dist/cjs/HttpConnection.js:256:35)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async HttpConnection._startInternal (/Users/user/Desktop/WebChat-Client-master/node_modules/@microsoft/signalr/dist/cjs/HttpConnection.js:172:41)
at async HttpConnection.start (/Users/user/Desktop/WebChat-Client-master/node_modules/@microsoft/signalr/dist/cjs/HttpConnection.js:75:9)
at async HubConnection._startInternal (/Users/user/Desktop/WebChat-Client-master/node_modules/@microsoft/signalr/dist/cjs/HubConnection.js:132:9)
at async HubConnection._startWithStateTransitions (/Users/user/Desktop/WebChat-Client-master/node_modules/@microsoft/signalr/dist/cjs/HubConnection.js:109:13)
at async start (/Users/user/Desktop/WebChat-Client-master/chat.js:10:5)
at async startApp (/Users/user/Desktop/WebChat-Client-master/chat.js:18:3) {
errorType: 'FailedToNegotiateWithServerError'
}
你告诉它连接到
http://127.0.0.1:7265/chathub
但连接被拒绝了。
任一:
运行服务器或更正 URL。