1.添加数据支持。

This commit is contained in:
facat 2019-06-18 18:18:53 +08:00
parent e20940de1f
commit 6204d44c8b
1 changed files with 11 additions and 6 deletions

17
main.py
View File

@ -1,17 +1,22 @@
from socketserver import BaseRequestHandler, TCPServer from socketserver import BaseRequestHandler, TCPServer
import db
class EchoHandler(BaseRequestHandler): class EchoHandler(BaseRequestHandler):
def handle(self): def handle(self):
print("Got connection from", self.client_address) print("Got connection from", self.client_address)
host=self.request.recv(1024) host = self.request.recv(1024)
print("Host is {host}".format(host=host)) print("Host is {host}".format(host=host))
if host: if host:
if host=='bwg'.encode('ascii'): latest_speed_dic = db.get_latest_speed()
self.request.sendall("50%\n".encode('ascii')) for server in latest_speed_dic:
print('send to bwg') if host == server.encode("ascii"):
if host=='hosteons'.encode('ascii'): speed = int(server["speed"])
self.request.sendall("80%\n".encode('ascii')) self.request.sendall(
"{weight}%\n".format(weight=speed).encode("ascii")
)
print("send to bwg with wight {weight}".format(weight=speed))
break
self.request.close() self.request.close()