Python实现TCP Server
# Python 3
import socketserver
class MyTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024)
respone = b'HTTP/1.1 200 OK\r\n\r\nOK'
self.request.send(respone)
if __name__ == "__main__":
server = socketserver.ThreadingTCPServer(('0.0.0.0', 8000), MyTCPHandler)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()
print('Bye')