-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
51 lines (41 loc) · 1.37 KB
/
server.py
File metadata and controls
51 lines (41 loc) · 1.37 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
import socket
from threading import *
filepath = "C:/Users/BAILEY/Programming/hackathon/stateFarm/pipe.txt"
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "127.0.0.1"
port = 8081
print(host)
print(port)
serversocket.bind((host, port))
keyWords = ["claim", "auto", "car", "vehicle", "rental", "quote", "home",
"house", "fire", "life", "status"]
class client(Thread):
def __init__(self, socket, address):
Thread.__init__(self)
self.sock = socket
self.addr = address
self.start()
def run(self):
while 1:
out = []
msg = self.sock.recv(1024).decode()
# print(msg)
print('Client sent:', msg)
for thing in keyWords:
if thing in msg.replace("auto", "car").replace("vehicle", "car").replace("home", "house"):
out.append(thing)
print(out)
y = ",".join(map(str, out))
with open(filepath, 'w') as f:
f.truncate()
f.write(y)
f.close()
if str(msg) == str("stop"):
serversocket.close()
break
self.sock.send(b'\nServer Recived Msg\n')
serversocket.listen(5)
print('server started and listening')
while 1:
clientsocket, address = serversocket.accept()
client(clientsocket, address)