-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
56 lines (42 loc) · 1.62 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
52
53
54
55
56
# ECE 5650
# Project 2 - Client Side
# Shubh Patel
# Reanna John
# 11/18/2020
from socket import *
from client_helperfunctions import *
from server_helperfunctions import compress_file, uncompress_file
SERVERNAME = 'localhost'
SERVERPORT = 12000
# dictionary to work as a switch
what_to_do = {
"search word": search_word,
"replace word": replace_word,
"reverse word": reverse_word,
"display file": display_file,
"exit": Exit,
}
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((SERVERNAME, SERVERPORT))
while clientSocket:
# ======= ask user which operation to do ======
print("Valid Operations: ",
"\t> thread - server sends back the thread serving the current operation",
"\t> Search Word - counts occurances of given word in given file",
"\t> Replace Word - replaces a given word by another given word in a given file",
"\t> Reverse Word",
"\t> Display File",
"\t> Exit", sep="\n")
userInput = input("What operation would you like to do? ").lower()
# =============================================
# ========= handle operation ==================
# print('DEBUG:', userInput)
if userInput == 'thread':
get_thread_name(clientSocket, userInput)
elif userInput in what_to_do.keys():
# preps server for search word function
clientSocket.send(bytes(userInput, 'utf-8'))
what_to_do[userInput](clientSocket)
else:
print('Command does not exist')
# =============================================