-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
38 lines (28 loc) · 894 Bytes
/
client.py
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
32
33
34
35
36
37
38
import socket
IP = socket.gethostbyname(socket.gethostname())
PORT = 4455
ADDR = (IP, PORT)
FORMAT = "utf-8"
SIZE = 1024
def main():
""" Staring a TCP socket. """
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
""" Connecting to the server. """
client.connect(ADDR)
""" Opening and reading the file data. """
file = open("datayt.txt", "r")
data = file.read()
""" Sending the filename to the server. """
client.send("yt.txt".encode(FORMAT))
msg = client.recv(SIZE).decode(FORMAT)
print(f"[SERVER]: {msg}")
""" Sending the file data to the server. """
client.send(data.encode(FORMAT))
msg = client.recv(SIZE).decode(FORMAT)
print(f"[SERVER]: {msg}")
""" Closing the file. """
file.close()
""" Closing the connection from the server. """
client.close()
if __name__ == "__main__":
main()