diff --git a/scripts/test-connection.js b/scripts/test-connection.js new file mode 100644 index 0000000..8c86e06 --- /dev/null +++ b/scripts/test-connection.js @@ -0,0 +1,135 @@ +#!/usr/bin/env node + +/** + * Test script to verify connection to Ross Ultrix system + * Usage: node scripts/test-connection.js + */ + +import { WebSocket } from 'ws'; +import dotenv from 'dotenv'; + +// Load environment variables +dotenv.config(); + +const ROSS_HOST = process.env.ROSS_TALK_HOST || '192.168.1.100'; +const ROSS_PORT = process.env.ROSS_TALK_PORT || '7788'; +const TIMEOUT = 10000; + +console.log('🔌 Testing connection to Ross Ultrix system...'); +console.log(` Host: ${ROSS_HOST}`); +console.log(` Port: ${ROSS_PORT}`); +console.log(''); + +async function testConnection() { + return new Promise((resolve, reject) => { + const wsUrl = `ws://${ROSS_HOST}:${ROSS_PORT}/rosstalk`; + console.log(`Attempting WebSocket connection to: ${wsUrl}`); + + const ws = new WebSocket(wsUrl, { + headers: { + 'Sec-WebSocket-Protocol': 'rosstalk' + } + }); + + const timeout = setTimeout(() => { + ws.close(); + reject(new Error('Connection timeout')); + }, TIMEOUT); + + ws.on('open', () => { + clearTimeout(timeout); + console.log('✅ Successfully connected to Ross Ultrix!'); + + // Send a test status request + console.log('📤 Sending status request...'); + ws.send(''); + }); + + ws.on('message', (data) => { + console.log('📥 Received response:', data.toString()); + ws.close(); + resolve('Connection test successful'); + }); + + ws.on('error', (error) => { + clearTimeout(timeout); + console.error('❌ Connection error:', error.message); + reject(error); + }); + + ws.on('close', (code, reason) => { + clearTimeout(timeout); + if (code === 1000) { + console.log('🔒 Connection closed normally'); + resolve('Connection test completed'); + } else { + console.log(`🔒 Connection closed with code: ${code}, reason: ${reason}`); + } + }); + }); +} + +async function testNetworkReachability() { + console.log('🌐 Testing network reachability...'); + + try { + // Simple TCP connection test + const { createConnection } = await import('net'); + + return new Promise((resolve, reject) => { + const socket = createConnection(parseInt(ROSS_PORT), ROSS_HOST); + + const timeout = setTimeout(() => { + socket.destroy(); + reject(new Error('Network timeout')); + }, 5000); + + socket.on('connect', () => { + clearTimeout(timeout); + console.log('✅ Network connection successful'); + socket.destroy(); + resolve('Network reachable'); + }); + + socket.on('error', (error) => { + clearTimeout(timeout); + console.error('❌ Network error:', error.message); + reject(error); + }); + }); + } catch (error) { + console.error('❌ Network test failed:', error.message); + throw error; + } +} + +async function main() { + try { + // First test basic network connectivity + await testNetworkReachability(); + console.log(''); + + // Then test WebSocket Ross Talk connection + await testConnection(); + + console.log(''); + console.log('🎉 All tests passed! Your Ross Ultrix system is reachable.'); + console.log(' You can now start the MCP server with: npm start'); + + } catch (error) { + console.log(''); + console.error('💥 Connection test failed!'); + console.error(' Error:', error.message); + console.log(''); + console.log('📋 Troubleshooting steps:'); + console.log(' 1. Check that your Ross Ultrix system is powered on'); + console.log(' 2. Verify the IP address in your .env file'); + console.log(' 3. Ensure Ross Talk is enabled on the Ultrix system'); + console.log(' 4. Check network connectivity and firewall settings'); + console.log(' 5. Verify the Ross Talk port (default 7788)'); + + process.exit(1); + } +} + +main();