-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_socket.py
More file actions
29 lines (25 loc) · 1.02 KB
/
import_socket.py
File metadata and controls
29 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import socket
# Server-Details
HOST = "0.0.0.0" # Hört auf alle verfügbaren Netzwerkinterfaces
PORT = 22504 # Der Port muss mit deinem ESP32-Code übereinstimmen
def start_mock_server():
# TCP/IP-Socket erstellen
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
server_socket.bind((HOST, PORT))
server_socket.listen(1)
print(f"Server läuft auf {HOST}:{PORT}")
while True:
print("Warte auf Verbindungen...")
client_socket, addr = server_socket.accept()
with client_socket:
print(f"Verbunden mit {addr}")
while True:
# Empfangene Daten lesen
data = client_socket.recv(1024)
if not data:
break
print(f"Empfangen: {data.decode()}")
# Optionale Antwort an den Client
client_socket.sendall(b"Nachricht empfangen")
if __name__ == "__main__":
start_mock_server()