• socket_sever实现多客户端并发


     1 #!/usr/bin/env python
     2 # -*- coding:utf-8 -*-
     3 import socketserver
     4 class mysever(socketserver.BaseRequestHandler):
     5     def handle(self):
     6         conn = self.request
     7         # 和之前创建socket是一样的
     8         conn.sendall(bytes('欢迎致电10086', encoding='utf-8'))
     9         while True:
    10             ret_bytes = conn.recv(1024)
    11             ret_str = str(ret_bytes, encoding='utf-8')
    12             if ret_str == 'q':
    13                 break
    14             conn.sendall(bytes(ret_str + 'ok', encoding='utf-8'))
    15 
    16 if __name__ =='__main__':
    17     sever = socketserver.ThreadingTCPServer(('127.0.0.1',9999,),mysever)
    18     sever.serve_forever()
  • 相关阅读:
    ElementUi
    Vue插件
    Vue-cli
    Vue进阶
    Vue组件
    Vue生命期钩子
    Vue基础
    Vue介绍
    logging模块
    time模块
  • 原文地址:https://www.cnblogs.com/Erick-L/p/6445376.html
Copyright © 2020-2023  润新知