Ejemplo n.º 1
0
 def handleClient(self,fd):
     print "Handling Client..."
     ch = ClientHandler(self.clients[fd])
     if not ch.handle():
         self.poller.unregister(fd)
         self.clients[fd].close()
         del self.clients[fd]
Ejemplo n.º 2
0
    def run(self):
        while True:
            running = self.running
            garbage = []
            # if the q is empty sleep for a second and return to the top of the loop
            if not self.q:
                time.sleep(1)
                continue
            else:
                # check if the set is full if it is start garbage collecting
                if len(running) > 0:
                    for thread in running:
                        if thread.is_alive() == False:
                            garbage.append(thread)
                            # print("Found a dead thread moving it to garbage")
                    # remove all dead threads from the garbage array
                    for trash in garbage:
                        running.remove(trash)
                        # print('Taking out all the trash threads')
                    # sleep for a second then return to the top of the loop

                    # continue
                # if there is room create and start the client thread then add it to the running set
                while len(running) < 5 and len(self.q) > 0:
                    c = self.q.popleft()
                    clientHandler = ClientHandler(c)
                    clientHandler.start()
                    running.add(clientHandler)
                    # print('Current status of the set is %s' % str(running))
                time.sleep(1)
Ejemplo n.º 3
0
    def new_conn(self):
        conn, addr = self.server.accept()
        conn.setblocking(0)

        self.poll.register(conn.fileno(), select.POLLIN)
        self.clients[conn.fileno()] = ClientHandler(conn, self.queues)

        serverStats['total_connections'] += 1
        serverStats['connections'] += 1
Ejemplo n.º 4
0
    def handle_client(self, conn, addr):
        cl = ClientHandler(conn, self.queues)
        try:
            while True:
                if cl.canRead() and not cl.handleRead():
                    raise socket.error
                if cl.canWrite() and not cl.handleWrite():
                    raise socket.error

        except socket.error, e:
            pass
Ejemplo n.º 5
0
    def run(self):
        while True:  #the servers main job is to just sit and accept clients, then pass them off to a handler thread
            con, addr = self.sock.accept()
            print('Connection made at IP: ', str(addr[0]))
            print('Passing off client..')
            client = ClientHandler(
                con, addr[0], self, self.update
            )  #creating the client handler thread, needs the connection object and IP the client is from
            client.start()
            self.currentCons.append([
                client, addr[0]
            ])  #adds in the connection to the current connections list
            self.displayClients()

        print('Closing server and connections..')
        self.sock.close()
        self.deleteAllClients()
        if self.update:
            self.updates("_________, SERVER SHUT DOWN", "______")
 def __init__(self, prefix, users, logger):
     self.prefix = prefix
     self.ackTime = str(datetime.datetime.now().time())
     self.clientHandler = ClientHandler(users)
     self.logger = logger