socket-多线程并发-server

#!/usr/bin/env python

import SocketServer

class MyTCPHandler(SocketServer.BaseRequestHandler):

 

  def handle(self):

    print 'Got anew connection from',self.client_address

    while True:

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

      if not data:

        print 'Lostconnection with',self.client_address

        break

      print'recv:',data

      #print"{}wrote:".format(self.client_address[0])

      #printself.data

     self.request.sendall(data.upper())

 

if __name__ == "__main__":

 HOST,PORT="192.168.2.110",99

  server =SocketServer.ThreadingTCPServer((HOST,PORT),MyTCPHandler)

  server.serve_forever()

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS