首页 > 代码库 > PYthon多线程服务器

PYthon多线程服务器

分为两部分,一部分用来更新数据,另一部分用来响应客户端的请求。


from SocketServer import TCPServer, StreamRequestHandler
from time import ctime

from SocketServer import ThreadingTCPServer
import traceback
import threading

Mutex = threading.Lock()
HOST = "127.0.0.1"
#HOST = "121.40.152.123"
PORT_Recv = 6000
ADDR_Recv = (HOST,PORT_Recv)
Int = [ i for i in range (101)]
dict_ele = {'001':'100'} 
for i in range(101):
    Key_ele = str(i)
    if len(Key_ele) == 1:
        Key_ele = '00' + Key_ele
        dict_ele.update({Key_ele:"100"})
    elif len(Key_ele) == 2:
        Key_ele = '0' + Key_ele
        dict_ele.update({Key_ele:"100"})
    else :
        dict_ele.update({Key_ele:"100"})




class Recv_Data_from_Vehicle_RequestHandle(StreamRequestHandler):
    def handle(self):
        #data = http://www.mamicode.com/self.rfile.readline()>

PYthon多线程服务器