SignalR

Seeking help to start SignalR server using Node. Here's my code: (white lie, I've had chatgpt on call to help resolve but no luck)
const { HubConnectionBuilder, LogLevel } = require("@microsoft/signalr");

// Create an HTTP server
const http = require("http");
const port = 5555;
const server = http.createServer();

// Start the server
server.listen(port, () => {
console.log(`Server started on port ${port}`);
});

// Create a SignalR connection
const hubConnection = new HubConnectionBuilder()
.withUrl(`http://localhost:${port}/chatHub`)
.configureLogging(LogLevel.Information) // Set log level (Information, Debug, etc.)
.build();

// Start the SignalR connection
hubConnection.start()
.then(() => {
console.log(`SignalR server started`);
})
.catch(error => {
console.error(`Error starting SignalR server: ${error}`);
});

// Handle events or messages here
// Example:
hubConnection.on('messageReceived', (user, message) => {
console.log(`Received message from ${user}: ${message}`);
});
const { HubConnectionBuilder, LogLevel } = require("@microsoft/signalr");

// Create an HTTP server
const http = require("http");
const port = 5555;
const server = http.createServer();

// Start the server
server.listen(port, () => {
console.log(`Server started on port ${port}`);
});

// Create a SignalR connection
const hubConnection = new HubConnectionBuilder()
.withUrl(`http://localhost:${port}/chatHub`)
.configureLogging(LogLevel.Information) // Set log level (Information, Debug, etc.)
.build();

// Start the SignalR connection
hubConnection.start()
.then(() => {
console.log(`SignalR server started`);
})
.catch(error => {
console.error(`Error starting SignalR server: ${error}`);
});

// Handle events or messages here
// Example:
hubConnection.on('messageReceived', (user, message) => {
console.log(`Received message from ${user}: ${message}`);
});
Console logs:
Server started on port 5555
[2023-09-25T17:52:40.776Z] Warning: Timeout from HTTP request.
[2023-09-25T17:52:40.778Z] Error: Failed to complete negotiation with the server: Error: A timeout occurred.
[2023-09-25T17:52:40.779Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: Error: A timeout occurred.
Error starting SignalR server: Error: Failed to complete negotiation with the server: Error: A timeout occurred.
Server started on port 5555
[2023-09-25T17:52:40.776Z] Warning: Timeout from HTTP request.
[2023-09-25T17:52:40.778Z] Error: Failed to complete negotiation with the server: Error: A timeout occurred.
[2023-09-25T17:52:40.779Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: Error: A timeout occurred.
Error starting SignalR server: Error: Failed to complete negotiation with the server: Error: A timeout occurred.
0 Replies
No replies yetBe the first to reply to this messageJoin