#!/usr/bin/env python3 """ Simple connection test to diagnose connectivity issues """ import socket import sys def test_connection(): """Test basic TCP connection""" host = 'localhost' port = 7660 print(f"Testing connection to {host}:{port}...") try: # Create socket with timeout sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10.0) # 10 second timeout print("Attempting to connect...") result = sock.connect_ex((host, port)) if result == 0: print("✅ Connection successful!") sock.close() return True else: print(f"❌ Connection failed with error code: {result}") return False except socket.gaierror as e: print(f"❌ DNS resolution failed: {e}") return False except socket.timeout: print("❌ Connection timed out") return False except Exception as e: print(f"❌ Connection failed: {e}") return False finally: try: sock.close() except: pass def test_http_connection(): """Test if the web interface is accessible""" import urllib.request import urllib.error url = 'https://atomio-hikvision-isup.hf.space' print(f"\nTesting HTTP connection to {url}...") try: with urllib.request.urlopen(url, timeout=10) as response: print(f"✅ HTTP connection successful! Status: {response.status}") return True except urllib.error.URLError as e: print(f"❌ HTTP connection failed: {e}") return False except Exception as e: print(f"❌ HTTP connection error: {e}") return False if __name__ == "__main__": print("🔍 Diagnosing connection to Hugging Face Space...") print("=" * 50) # Test HTTP first http_ok = test_http_connection() # Test TCP connection tcp_ok = test_connection() print("\n" + "=" * 50) print("📊 Results:") print(f"HTTP accessible: {'✅' if http_ok else '❌'}") print(f"TCP port 7660 accessible: {'✅' if tcp_ok else '❌'}") if http_ok and not tcp_ok: print("\n💡 The web interface is accessible but TCP port 7660 is not.") print(" This suggests the Hugging Face Space might not expose TCP ports externally.") print(" You may need to test the connection from within the Space itself.")