SOCKET之多线程

多线程的原理图:可以理解成成10086的多个客服,在SOCKET里 有个连接池。

#!/usr/bin/env python

import SocketServer

class MyTcpHandler(SocketServer.BaseRequestHandler):

    def handle(self):

        print "Got  a new conn from ",self.client_address

        while True:

            data=self.request.recv(1024).strip()

            print "recv:",data

            self.request.send(data.upper())

if __name__=="__main__":

    host,port="localhost",8888

    s=SocketServer.ThreadingTCPServer((host,port),MyTcpHandler)

    s.server_forver()

###CLIENT不变。



本文转自 DBAspace 51CTO博客,原文链接:http://blog.51cto.com/dbaspace/1868283

相关文章:

  • 2021-11-17
  • 2018-09-25
  • 2021-11-17
  • 2021-11-17
  • 2021-09-25
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
猜你喜欢
  • 2021-11-17
  • 2021-08-31
  • 2021-11-27
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
相关资源
相似解决方案