-
Notifications
You must be signed in to change notification settings - Fork 0
/
portTestingServer.py
46 lines (37 loc) · 1012 Bytes
/
portTestingServer.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
45
46
import socket
import os
from imageClassifier import Rekognize
rek = Rekognize()
server_host = '10.0.0.40'
server_port = 65432
host = '10.0.0.5'
port = server_port
buffer_size = 4096
separator = "<SEPARATOR>"
folder = "Images/"
while True:
s = socket.socket()
s.bind((server_host,server_port))
s.listen(5)
print(f"Listening as {server_host}:{server_port}")
client_socket, address = s.accept()
print(f"{address[0]}:{address[1]} is connected")
received = client_socket.recv(buffer_size).decode()
filename, filesize = received.split(separator)
filename = os.path.basename(filename)
filesize = int(filesize)
with open(folder + filename, "wb") as f:
while True:
bytes_read = client_socket.recv(buffer_size)
if not bytes_read:
break
f.write(bytes_read)
client_socket.close()
s.close()
name = rek.classify(folder + filename)
s = socket.socket()
print(f"Connection to {host}:{port}")
s.connect((host, port))
print(f"Found {name} in {filename}")
s.send(name.encode())
s.close()