forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceive_file.py
More file actions
Latest commit
27 lines (20 loc) · 585 Bytes
/
Copy pathreceive_file.py
File metadata and controls
27 lines (20 loc) · 585 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
importsocket
defmain():
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host=socket.gethostname()
port=12312
sock.connect((host, port))
sock.send(b"Hello server!")
withopen("Received_file", "wb") asout_file:
print("File opened")
print("Receiving data...")
whileTrue:
data=sock.recv(1024)
ifnotdata:
break
out_file.write(data)
print("Successfully received the file")
sock.close()
print("Connection closed")
if__name__=="__main__":
main()