SOCKET之多线程_localhost

多线程的原理图:可以理解成成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不变。