Add auto-discovery support (UDP discovery responder & subnet scanner) and implement virtual screen MCP server

This commit is contained in:
Adolfo Reyna
2026-06-03 14:29:49 -04:00
parent 81e7b15b61
commit 070390355e
8 changed files with 2115 additions and 2 deletions
+21
View File
@@ -26,9 +26,30 @@ class MCPServer:
# Set socket to non-blocking so the main loop can run animations concurrently
self.sock.setblocking(False)
print(f"MCP server listening on port {port}...")
# Setup UDP socket for auto-discovery on port 5000
try:
self.udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.udp_sock.bind(('', 5000))
self.udp_sock.setblocking(False)
print("UDP Discovery responder listening on port 5000...")
except Exception as ue:
print("Failed to bind UDP Discovery socket: {}".format(ue))
self.udp_sock = None
def update(self):
"""Check for incoming HTTP requests and handle them non-blockingly."""
# 1. Handle UDP Discovery queries
if hasattr(self, 'udp_sock') and self.udp_sock is not None:
try:
data, addr = self.udp_sock.recvfrom(128)
if data == b"DISCOVER_SCREEN":
self.udp_sock.sendto(b"SCREEN_IP_80", addr)
except OSError:
pass
# 2. Check for incoming HTTP TCP connections
if self.sock is None:
return