mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Create codespell.yml (#1698)
* fixup! Format Python code with psf/black push * Create codespell.yml * fixup! Format Python code with psf/black push
This commit is contained in:
23
file_transfer/receive_file.py
Normal file
23
file_transfer/receive_file.py
Normal file
@ -0,0 +1,23 @@
|
||||
if __name__ == "__main__":
|
||||
import socket # Import socket module
|
||||
|
||||
sock = socket.socket() # Create a socket object
|
||||
host = socket.gethostname() # Get local machine name
|
||||
port = 12312
|
||||
|
||||
sock.connect((host, port))
|
||||
sock.send(b"Hello server!")
|
||||
|
||||
with open("Received_file", "wb") as out_file:
|
||||
print("File opened")
|
||||
print("Receiving data...")
|
||||
while True:
|
||||
data = sock.recv(1024)
|
||||
print(f"data={data}")
|
||||
if not data:
|
||||
break
|
||||
out_file.write(data) # Write data to a file
|
||||
|
||||
print("Successfully got the file")
|
||||
sock.close()
|
||||
print("Connection closed")
|
Reference in New Issue
Block a user