def main(): # ok, let's start by opening a log global log log = ms.logger(LOGFILE) if log.logfile == None: print("Failed to open log! Logging to console instead.") # init the client pool clientpool = Queue(0) for x in xrange(SERVTHREADS): servthread(clientpool, DEFAULTCOL).start() # create server object, bind to localhost:LPORT, and start listening log.logline("INFO: Starting musicshelf server (elevator) on port " + str(LPORT) + ".") server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('',LPORT)) server.listen(BACKLOG) log.logline("INFO: All good so far, server is now listening.") # and now we populate the client pool with connections try: while True: clientpool.put(server.accept()) except KeyboardInterrupt: print("Got control-c, closing...") log.logline(log, "INFO: server going down!") server.close() log.logfile.close() quit()
def __init__(self, pool, fn): self.pool = pool # the client pool try: self.col = open(fn, 'r') # file object except IOError: self.col = None self.client = None # a particular connection socket self.addr = '' # remote address, for easier access self.inst = None # thread-specific colfile instance threading.Thread.__init__(self) self.name = self.getName() self.tlog = ms.logger(self.name+'.log') # dunno if I'll use this, but it's here in case