hikvision-isup / test /test_connection_simple.py
Lewis Kimaru
feat: add WebSocket and HTTP tunnels for ISUP protocol to bypass HF port limitations
5003a03
Raw History Blame Contribute Delete
2.51 kB
#!/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.")