Skip to content

Update receive_file.py #8541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2023
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()