-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_code.py
More file actions
72 lines (65 loc) · 2.46 KB
/
client_code.py
File metadata and controls
72 lines (65 loc) · 2.46 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import socket
def getchar():
#Returns a single character from standard input
import tty, termios, sys
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def menu():
print("**********************************************************")
print("* *")
print("* ********* *")
print("* ********* *")
print("* ********* *")
print("* ************************* *")
print("* ************************* *")
print("* ************************* *")
print("* ************************* *")
print("* ********* *")
print("* ********* *")
print("* ********* *")
print("* *")
print("* *")
print("* Press C to Run Emergency Chatbot(open server first) *")
print("* Press E to exit *")
print("* *")
print("**********************************************************")
while True:
ch=getchar()
if(ch=="e"):
quit()
if(ch=="c"):
break
menu()
#name=input("What is your full name?\n")
#problem=("Please describe your situation.")
#connection to ChatBot
host = '127.0.0.1'
port = 5001
count = 0
thisSocket = socket.socket()
thisSocket.connect((host,port))
#Reading first message to ChatBot
message = "client"
#Continue conversation with ChatBot until end is types
while message != "end":
#send message to Chatbot
thisSocket.send(message.encode())
#Receive Message from ChatBot
RMess = thisSocket.recv(1024).decode()
#Print message from ChatBot
print('Emergency Chatbot: '+RMess)
#Get user message to ChatBot
message = input("Message to ChatBot: ")
#Close Socket
thisSocket.close()
#Display conversation is over
print("Conversation between user and ChatBot Ended")
#Check if running directly from this file
if __name__ == '__main__':
Main()