-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
44 lines (35 loc) · 1.05 KB
/
server.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import socket
from PIL import Image
import io
import json
import geo
def handle_client(client_socket):
# Empfange die Bildgröße
size = int.from_bytes(client_socket.recv(4), 'big')
# Empfange das Bild
image_data = b''
while len(image_data) < size:
packet = client_socket.recv(4096)
if not packet:
break
image_data += packet
# Lade das Bild
image = Image.open(io.BytesIO(image_data))
# Verarbeite das Bild
result = geo.identify(image, 5)
# Konvertiere das Ergebnis in JSON
result_json = json.dumps(result)
# Sende die Ergebnisse zurück
client_socket.sendall(result_json.encode('utf-8'))
client_socket.close()
def main():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', 9999))
server.listen(5)
print("Server läuft...")
while True:
client_socket, addr = server.accept()
print(f"Verbindung von {addr} akzeptiert")
handle_client(client_socket)
if __name__ == "__main__":
main()