()
| 2 | |
| 3 | |
| 4 | def main(): |
| 5 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 6 | host = socket.gethostname() |
| 7 | port = 12312 |
| 8 | |
| 9 | sock.connect((host, port)) |
| 10 | sock.send(b"Hello server!") |
| 11 | |
| 12 | with open("Received_file", "wb") as out_file: |
| 13 | print("File opened") |
| 14 | print("Receiving data...") |
| 15 | while True: |
| 16 | data = sock.recv(1024) |
| 17 | if not data: |
| 18 | break |
| 19 | out_file.write(data) |
| 20 | |
| 21 | print("Successfully received the file") |
| 22 | sock.close() |
| 23 | print("Connection closed") |
| 24 | |
| 25 | |
| 26 | if __name__ == "__main__": |