-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
52 lines (43 loc) · 1.28 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import socket
client = socket.socket()
client.connect(('localhost',9999)) #can be given any IP address
msg=client.recv(1024).decode()
print(msg)
while True:
choice = input("1. Create a file\n 2. Delete a file\n 3. Edit a file\n 4. Read a file\n 5. End connection\n Enter a choice: ")
if choice == "1":
client.send(bytes("1","utf-8"))
file = input("Enter file name: ")
client.send(bytes(file,"utf-8"))
print_msg=client.recv(1024).decode()
print(print_msg)
print("\n")
elif choice == "2":
client.send(bytes("2","utf-8"))
file = input("Enter file name: ")
client.send(bytes(file,"utf-8"))
print_msg=client.recv(1024).decode()
print(print_msg)
print("\n")
elif choice == "3":
client.send(bytes("3","utf-8"))
file = input("Enter file name: ")
client.send(bytes(file,"utf-8"))
content = input("Enter the text to be added: ")
client.send(bytes(content,"utf-8"))
print_msg=client.recv(1024).decode()
print(print_msg)
print("\n")
elif choice == "4":
client.send(bytes("4","utf-8"))
file = input("Enter file name: ")
client.send(bytes(file,"utf-8"))
print_msg=client.recv(1024).decode()
print(print_msg)
print("\n")
elif choice == "5":
client.send(bytes("5","utf-8"))
print("The connection has been ended.")
quit()
else:
print("Invalid choice!")