You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1008 B

import socketserver
class Handler_TCPServer(socketserver.BaseRequestHandler):
"""
The TCP Server class for demonstration.
Note: We need to implement the Handle method to exchange data
with TCP client.
"""
def handle(self):
# self.request - TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print("{} sent:".format(self.client_address[0]))
print(self.data)
# just send back ACK for data arrival confirmation
self.request.sendall("ACK from TCP Server".encode())
def ping(self, param):
return "PONG"
def command_pass(self, param):
return param == self.password
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
# Init the TCP server object, bind it to the localhost on 9999 port
tcp_server = socketserver.TCPServer((HOST, PORT), Handler_TCPServer)
# Activate the TCP server.
# To abort the TCP server, press Ctrl-C.
tcp_server.serve_forever()