-
Notifications
You must be signed in to change notification settings - Fork 0
/
server code.py
63 lines (62 loc) · 1.64 KB
/
server code.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import socket
#import multiprocessing as mp
import time
import cv2
ser=socket.socket()
ser.bind((socket.gethostname(),1233))
print(ser.getsockname())
ser.listen(5)
def view():
"""try:"""
#print("executing p1")
with open("./pro/names.txt","r") as f1:
l=f1.read()
f1.close()
l=l[:len(l)-1]
#print(l)
li=l.split(",")
#li.reverse()
#print(li)
for i in li:
if i != "":
l=cv2.imread("./pro/"+i,-1)
cv2.imshow("image",l)
cv2.waitKey(5000)
cv2.destroyAllWindows()
#time.sleep(5)
#l.close()
"""except:
with open("./pro/names.txt","w") as f1:
f.write("")
f1.close()"""
while True:
try:
view()
print("Waiting for connection")
c,add=ser.accept()
print("Connected",add)
#p2.acquire()
f_name=c.recv(1024).decode("utf-8")
if f_name:
with open("./pro/names.txt","a") as f1:
f1.write(f_name+",")
f1.close()
print(f_name)
with open("./pro/"+f_name,"ab") as f:
while 1:
l=c.recv(130990)
#l=c.recv(130990)
if len(l)<=0:
break
f.write(l)
view()
f.close()
c.close()
else:
print("picture is not received")
with open("./pro/names.txt","w") as f1:
f1.write("")
#p2.release()
except:
print("Error occored")
c.close()