MyStreamRequestHandlerr

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@version: 001
@author: jianpan
@file: MySocketServer.py
@time: 2017/6/3 11:00
"""

# -*- coding:utf-8 -*-

from SocketServer import ThreadingTCPServer, StreamRequestHandler
import traceback


class MyStreamRequestHandlerr(StreamRequestHandler):
    def handle(self):
        try:
            while True:
                data = self.rfile.readline().strip()
                print "receive from (%r):%r" % (self.client_address, data)
                self.wfile.write(data.upper())
        except:
            traceback.print_exc()
            print 'exit'
            # break


if __name__ == "__main__":
    host = ""  # 主机名,可以是ip,像localhost的主机名,或""
    port = 9999  # 端口
    addr = (host, port)

    # ThreadingTCPServer从ThreadingMixIn和TCPServer继承
    # class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
    server = ThreadingTCPServer(addr, MyStreamRequestHandlerr)
    server.serve_forever()


posted @ 2017-06-03 11:47  我的大金金  阅读(259)  评论(0编辑  收藏  举报