-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconnectUser.py
33 lines (28 loc) · 918 Bytes
/
connectUser.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
from recognition import rec
import socket
import pickle
import cv2
def connUser(conn, addr):
while True:
mess = conn.recv(1024)
message = mess.decode()
if message == "download image":
conn.send(b"done")
leng = conn.recv(1024)
length = leng.decode()
conn.send(length.encode())
image = bytearray() # Массив для сохранения изображения
s = 0
while True:
m = conn.recv(1024)
image += m
s += len(m)
if not m or s == int(length):
break
data = rec(pickle.loads(image))
byteDate = pickle.dumps(data)
conn.send(byteDate)
if not mess:
print("close", addr)
conn.close() # Выключене сокета
break