Files
god_eye_android/server_test.py
2025-10-04 11:55:35 +09:00

124 lines
4.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Простой скрипт для тестирования доступности сервера
"""
import socket
import requests
import sys
def test_tcp_connection(host, port):
"""Тестирует TCP подключение к серверу"""
try:
print(f"🔍 Testing TCP connection to {host}:{port}")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((host, port))
sock.close()
if result == 0:
print(f"✅ TCP connection successful to {host}:{port}")
return True
else:
print(f"❌ TCP connection failed to {host}:{port} (error: {result})")
return False
except Exception as e:
print(f"❌ TCP connection error: {e}")
return False
def test_http_connection(url):
"""Тестирует HTTP подключение к серверу"""
try:
print(f"🌐 Testing HTTP connection to {url}")
response = requests.get(url, timeout=5)
print(f"✅ HTTP connection successful: {response.status_code}")
return True
except Exception as e:
print(f"❌ HTTP connection error: {e}")
return False
def test_socket_io_endpoint(url):
"""Тестирует Socket.IO endpoint"""
try:
socket_io_url = f"{url}/socket.io/"
print(f"🔌 Testing Socket.IO endpoint: {socket_io_url}")
response = requests.get(socket_io_url, timeout=5)
print(f"✅ Socket.IO endpoint accessible: {response.status_code}")
if "socket.io" in response.text.lower():
print("✅ Socket.IO server detected")
return True
except Exception as e:
print(f"❌ Socket.IO endpoint error: {e}")
return False
def test_emulator_connection(port):
"""Тестирует подключение с адреса эмулятора Android"""
try:
print(f"📱 Testing Android emulator connection to localhost:{port}")
# Тестируем localhost (это то, что видит эмулятор как 10.0.2.2)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex(("127.0.0.1", port))
sock.close()
if result == 0:
print(f"✅ Emulator connection to localhost:{port} successful")
return True
else:
print(f"❌ Emulator connection to localhost:{port} failed (error: {result})")
return False
except Exception as e:
print(f"❌ Emulator connection error: {e}")
return False
def main():
server_ip = "192.168.219.108"
server_port = 3001
server_url = f"http://{server_ip}:{server_port}"
print("🚀 Starting server connectivity test")
print(f"📍 Target: {server_url}")
print("-" * 50)
# Тест 1: TCP подключение
tcp_ok = test_tcp_connection(server_ip, server_port)
# Тест 2: HTTP подключение
http_ok = test_http_connection(server_url)
# Тест 3: Socket.IO endpoint
socketio_ok = test_socket_io_endpoint(server_url)
# Тест 4: Эмулятор Android (localhost)
emulator_ok = test_emulator_connection(server_port)
print("-" * 50)
print("📊 РЕЗУЛЬТАТЫ ТЕСТИРОВАНИЯ:")
print(f" TCP connection: {'✅ OK' if tcp_ok else '❌ FAIL'}")
print(f" HTTP connection: {'✅ OK' if http_ok else '❌ FAIL'}")
print(f" Socket.IO endpoint: {'✅ OK' if socketio_ok else '❌ FAIL'}")
print(f" Emulator access: {'✅ OK' if emulator_ok else '❌ FAIL'}")
if tcp_ok and http_ok and socketio_ok:
print("\n🎉 Сервер полностью доступен!")
if emulator_ok:
print(" Android эмулятор сможет подключаться через 10.0.2.2")
else:
print(" ⚠️ Эмулятор может не подключиться - сервер должен слушать на 0.0.0.0")
else:
print("\n🚨 ПРОБЛЕМЫ С СЕРВЕРОМ:")
if not tcp_ok:
print(" - Сервер не отвечает на TCP подключения")
print(" - Проверьте, запущен ли сервер на порту 3001")
if not http_ok:
print(" - HTTP сервер недоступен")
print(" - Проверьте конфигурацию веб-сервера")
if not socketio_ok:
print(" - Socket.IO endpoint недоступен")
print(" - Проверьте настройки Socket.IO сервера")
if not emulator_ok:
print(" - Эмулятор не сможет подключиться")
print(" - Запустите сервер с bind на 0.0.0.0:3001")
if __name__ == "__main__":
main()