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}`);
});