Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219· AnthropicHugging Face LMArena Human Preference 140K

give node.js to connect to signalr that can register, send and receive message for testing

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro’s answer.
  1. User

    give node.js to connect to signalr that can register, send and receive message for testing

  2. Claude Assistant

    Here's a Node.js script to connect to SignalR, register, send and receive messages for testing:

    const signalR = require('@microsoft/signalr');
    
    // Create connection
    const connection = new signalR.HubConnectionBuilder()
      .withUrl('http://localhost:5000/chatHub')  // Replace with your SignalR hub URL
      .configureLogging(signalR.LogLevel.Information)
      .build();
    
    // Handle connection events
    connection.onclose(async () => {
      console.log('Connection closed');
      await start();
    });
    
    // Register handlers for incoming messages
    connection.on('ReceiveMessage', (user, message) => {
      console.log(`${user}: ${message}`);
    });
    
    // Start the connection
    async function start() {
      try {
        await connection.start();
        console.log('Connected to SignalR hub');
        
        // Register user after connection
        await connection.invoke('Register', 'TestUser');
        console.log('Registered as TestUser');
        
        // Send a test message
        await connection.invoke('SendMessage', 'TestUser', 'Hello, this is a test message');
        console.log('Test message sent');
      } catch (err) {
        console.error('Error connecting to SignalR hub:', err);
        setTimeout(start, 5000); // Retry connection after 5 seconds
      }
    }
    
    // Start the connection
    start();
    
    // Keep the process running
    process.stdin.resume();
    
    // Optional: Handle user input to send messages
    process.stdin.on('data', async (data) => {
      const message = data.toString().trim();
      if (message) {
        await connection.invoke('SendMessage', 'TestUser', message);
      }
    });
    

    Would you like me to explain or break down this code?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.