mySocket
Introduction
Using python language to complete socket multi-threaded programming and pseudo-intelligent communication through dictionary set.
The following shows part of the source code
.
Server.py
import socket
import threading
import time
import os
#字典集返回数据
def getAnswer(c_data):
words = {'how are you?': 'Fine,thank you.', # 字典集
'hi': 'hello',
'hello': 'hello',
'how old are you?': '20',
'what is your name?': 'Andel,
"what's your name?": 'Andel',
'where do you work?': 'Beijing',
'bye': 'Bye'
}
flag = 0
lst = list(words.keys())
for i in range(len(lst)):
if len(os.path.commonprefix([c_data, lst[i]])) > len(lst[i]) * 0.8:
flag = 1
return words.get(lst[i])
if flag == 0:
return "Sorry for that, I don