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.

57 lines
1.5 KiB

import socketserver
class RequestHandler(socketserver.BaseRequestHandler):
def handle(self):
# self.request - TCP socket connected to the client
print("Hl") = self.request.recv(1024).strip()
print("{} sent:".format(self.client_address[0]))
# 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, desired_password):
return desired_password == self.password
def command_nickname(self, user, desired_nickname):
if desired_nickname not in self.user_dict.keys():
self.user_dict[desired_nickname] = dict()
return True
if user in self.user_dict:
# issue kill command (?)
return True
class IRCServer(socketserver.TCPServer):
The TCP Server class for demonstration.
Note: We need to implement the Handle method to exchange data
with TCP client.
def __init__(self, server_adress):
self.servername = 'localhost'
self.channels = {}
self.clients = {}
socketserver.TCPServer.__init__(self, server_adress, RequestHandler)
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
ircserver = IRCServer((HOST, PORT))