forked from justEhmadSaeed/Python-Sockets-File-Transfer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
31 lines (23 loc) · 629 Bytes
/
client.py
File metadata and controls
31 lines (23 loc) · 629 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import socket
# Initialize Socket Instance
sock = socket.socket()
print ("Socket created successfully.")
# Defining port and host
port = 8800
host = 'localhost'
# Connect socket to the host and port
sock.connect((host, port))
print('Connection Established.')
# Send a greeting to the server
sock.send('A message from the client'.encode())
# Write File in binary
file = open('client-file.txt', 'wb')
# Keep receiving data from the server
line = sock.recv(1024)
while(line):
file.write(line)
line = sock.recv(1024)
print('File has been received successfully.')
file.close()
sock.close()
print('Connection Closed.')