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

该博客介绍了一个使用Python实现的多线程socket服务器,能够通过字典集进行简单的智能交流。服务器监听客户端连接,接收消息并使用线程发送回复。客户端则持续发送用户输入的数据直到输入'exit'退出。博主提到了尝试使用开源第三方库实现更智能的聊天功能,但目前无法免费测试。源代码可供学习,不应用于商业目的。
最低0.47元/天 解锁文章
2634

被折叠的 条评论
为什么被折叠?



