commit 8ff97d2a65eff7a38caf1863f7150047a45b7bc0 Author: facat Date: Tue Jun 18 17:50:50 2019 +0800 1.第一次提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv diff --git a/main.py b/main.py new file mode 100644 index 0000000..cc786eb --- /dev/null +++ b/main.py @@ -0,0 +1,20 @@ +from socketserver import BaseRequestHandler, TCPServer + + +class EchoHandler(BaseRequestHandler): + def handle(self): + print("Got connection from", self.client_address) + 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')) + self.request.close() + + +if __name__ == "__main__": + serv = TCPServer(("", 20000), EchoHandler) + serv.serve_forever()