1.添加数据支持。
This commit is contained in:
parent
e20940de1f
commit
6204d44c8b
17
main.py
17
main.py
|
|
@ -1,17 +1,22 @@
|
|||
from socketserver import BaseRequestHandler, TCPServer
|
||||
import db
|
||||
|
||||
|
||||
class EchoHandler(BaseRequestHandler):
|
||||
def handle(self):
|
||||
print("Got connection from", self.client_address)
|
||||
host=self.request.recv(1024)
|
||||
host = self.request.recv(1024)
|
||||
print("Host is {host}".format(host=host))
|
||||
if host:
|
||||
if host=='bwg'.encode('ascii'):
|
||||
self.request.sendall("50%\n".encode('ascii'))
|
||||
print('send to bwg')
|
||||
if host=='hosteons'.encode('ascii'):
|
||||
self.request.sendall("80%\n".encode('ascii'))
|
||||
latest_speed_dic = db.get_latest_speed()
|
||||
for server in latest_speed_dic:
|
||||
if host == server.encode("ascii"):
|
||||
speed = int(server["speed"])
|
||||
self.request.sendall(
|
||||
"{weight}%\n".format(weight=speed).encode("ascii")
|
||||
)
|
||||
print("send to bwg with wight {weight}".format(weight=speed))
|
||||
break
|
||||
self.request.close()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue