2023-03-31 14:08:13 +00:00
|
|
|
import socket
|
|
|
|
|
2019-08-07 13:44:48 +00:00
|
|
|
|
2023-03-31 14:08:13 +00:00
|
|
|
def main():
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
host = socket.gethostname()
|
2019-08-07 13:44:48 +00:00
|
|
|
port = 12312
|
|
|
|
|
|
|
|
sock.connect((host, port))
|
2019-10-05 05:14:13 +00:00
|
|
|
sock.send(b"Hello server!")
|
2019-08-07 13:44:48 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
with open("Received_file", "wb") as out_file:
|
|
|
|
print("File opened")
|
|
|
|
print("Receiving data...")
|
2019-08-07 13:44:48 +00:00
|
|
|
while True:
|
|
|
|
data = sock.recv(1024)
|
|
|
|
if not data:
|
|
|
|
break
|
2023-03-31 14:08:13 +00:00
|
|
|
out_file.write(data)
|
2019-08-07 13:44:48 +00:00
|
|
|
|
2023-03-31 14:08:13 +00:00
|
|
|
print("Successfully received the file")
|
2019-08-07 13:44:48 +00:00
|
|
|
sock.close()
|
2019-10-05 05:14:13 +00:00
|
|
|
print("Connection closed")
|
2023-03-31 14:08:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|