-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
30 lines (23 loc) · 690 Bytes
/
client.py
File metadata and controls
30 lines (23 loc) · 690 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
import socket
server = socket.gethostbyname(socket.gethostname())
port = 2200
encoding_format = 'utf-8'
size = 1024
def client():
#Create socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((server,port))
#Open file with read mode.
file = open(input("Arquivo: "),"r")
data = file.read()
#Sent filename
client.send("arquivo.txt".encode(encoding_format))
msg = client.recv(size).decode(encoding_format)
print(f"[SERVER]: {msg}")
#Sent file
client.send(data.encode(encoding_format))
msg = client.recv(size).decode(encoding_format)
print(f"[SERVER]: {msg}")
file.close()
client.close()
client()