python 多线程队列套接字,python多线程队列,#server端im
python 多线程队列套接字,python多线程队列,#server端im
#server端
import socketimport selectorsimport threadingfrom threading import Threadimport timeimport queueselector = selectors.DefaultSelector()socket_server = socket.socket()address_server = (‘0.0.0.0‘,8080)socket_server.bind(address_server)socket_server.listen(1000)q = queue.Queue(5)class Producer(Thread): ‘‘‘进队 初始化套接字 套接字入队 ‘‘‘ def __init__(self, q, socket_server): super().__init__() self.q = q self.socket_server = socket_server def run(self): while True: connect,address = self.socket_server.accept() self.q.put(connect)class Conmuer(Thread): ‘‘‘出队 套接字出队 ‘‘‘ def __init__(self, q): super().__init__() self.q = q def run(self): while True: connect = self.q.get() print(type(connect)) massage = connect.recv(1024) if massage: connect.send(massage) else: connect.close() # self.q.task_done()producer = Producer(q, socket_server)conmuer = Conmuer(q)producer.start()conmuer.start()client端
import socketimport timesocket = socket.socket()address = (‘127.0.0.1‘,8080)socket.connect(address)massage_send = input(‘请输入‘)massage_send = bytes(massage_send, encoding=‘utf-8‘)socket.send(massage_send)massage_rev = str(socket.recv(1024), encoding=‘utf-8‘)print(massage_rev)
python 多线程队列套接字
相关内容
- python匹配两个字符串中间的字符串,python匹配,问题:使
- python中使用指定GPU,python使用指定GPU,import oso
- 【bugRecord4】Fatal error in launcher: Unable to create process usi
- python之文件函数之作业,python函数作业,1、写函数,用
- python之gunicorn的配置,pythongunicorn,python常见的w
- python基础(六),python基础, 格式化输出有两种
- 使用Python访问微信,使用Python访问,itchat是一个开
- python的socket的学习,pythonsocket学习,一、Socket相关
- Python中where()函数的用法,pythonwhere,where()的用法
- 复制一个Python全部环境到另一个环境,python另一个,导出
评论关闭