Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions file_transfer/receive_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
if __name__ == "__main__":
import socket # Import socket module
import socket


sock = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 12312

sock.connect((host, port))
Expand All @@ -13,11 +14,14 @@
print("Receiving data...")
while True:
data = sock.recv(1024)
print(f"{data = }")
if not data:
break
out_file.write(data) # Write data to a file
out_file.write(data)

print("Successfully got the file")
print("Successfully received the file")
sock.close()
print("Connection closed")


if __name__ == "__main__":
main()