-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVA_server.py
55 lines (37 loc) · 1.02 KB
/
VA_server.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
from socket import *
from threading import *
from main import query
from System import speak
class ChatThread(Thread):
mute = False
"""docstring for ChatThread"""
def __init__(self, con):
Thread.__init__(self)
self.con = con
def run(self):
name = current_thread().getName()
while True:
if name=='sender':
data = input('Enter your massage : ')
self.con.send(bytes(data,'utf-8'))
elif name=='receiver':
recData = self.con.recv(1024).decode()
print('command : ',recData)
try:
output = query(recData)
speak(output)
except Exception as e:
print(e)
print('sorry but an unexpected error occured :(')
host = input('Enter host IP: ')
server = socket(AF_INET,SOCK_STREAM)
server.bind((host, 1131))
print('binding the port :', 1131)
server.listen(4)
conn,add = server.accept()
sender = ChatThread(conn)
sender.setName('sender')
receiver = ChatThread(conn)
receiver.setName('receiver')
sender.start()
receiver.start()