-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathsend_file.py
More file actions
36 lines (26 loc) · 769 Bytes
/
send_file.py
File metadata and controls
36 lines (26 loc) · 769 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
32
33
34
35
36
import socket
def send_file(filename: str = "textfile.txt", testing: bool = False) -> None:
port = 4412
sock = socket.socket()
host = socket.gethostname()
sock.bind((host, port))
sock.listen(5)
print("server jalan..!")
while True:
conn, addr = sock.accept()
print(f"terkoneksi.. ke {addr}")
data = conn.recv(1024)
print(f"diterima .. {data}")
with open(filename, "rb") as in_file:
data = in_file.read(1024)
while data:
conn.send(data)
data = in_file.read(1024)
print("terkirim")
conn.close()
if testing:
break
sock.shutdown(1)
sock.close()
if __name__ == "__main__":
send_file()