forked from larymak/Python-project-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_full_stack.py
More file actions
31 lines (28 loc) · 843 Bytes
/
Copy pathtest_full_stack.py
File metadata and controls
31 lines (28 loc) · 843 Bytes
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
import socket
result_file = "resultfile2_server.png"
input_file = "f1.jpg"
def main(address:tuple[str,int]):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(address)
sock.settimeout(10)
with open(input_file, "rb") as f:
sock.send(f.read())
res_buf = b''
try:
while True:
try:
res = sock.recv(1)
res_buf += res
if 0 == len(res):
sock.close()
with open(result_file, "wb") as f:
f.write(res_buf)
break
except socket.timeout:
with open(result_file, "wb") as f:
f.write(res_buf)
break
finally:
sock.close()
if "__main__" == __name__:
main(("localhost", 3535))