def send(self): while self.connected: if self.out_buffer == "": try: new_out_buffer = self.out_queue.get(True, 1) # blocks for a while self.out_buffer = buffrify.create_pack(str(new_out_buffer)) except Queue.Empty: pass if self.out_buffer != "": sent = self.s.send(self.out_buffer) if sent != len(self.out_buffer): print "lyckades inte tömma hela" self.out_buffer = self.out_buffer[sent:] else: self.out_buffer = "" if time.time()-self.timestamp > self.pingtime: print "server has pinged out" self.s.shutdown(socket.SHUT_RDWR) self.s.close() self.connected = False print "Du har stängt av allt i socketen" try: self.s.shutdown(socket.SHUT_RDWR) self.s.close() except socket.error: print "Socket är redan stängd" if not self.KeyboardInterrupt: self.reconnect()
pack = packet.Packet.from_str(read) print "laggar till %s=>%s" % (pack.type, str(pack.data)) if pack.type in clientrequests: clientrequests[pack.type](connection, pack) else: to_be_removed.append(sock.fileno()) for sock in write_list: connection = connections[sock.fileno()] if connection.out_buffer == "" and \ not connection.out_queue.empty(): #print "skriver till %s (%s)" % (connection.id, connection.user) abba = connection.out_queue.get() connection.out_buffer = buffrify.create_pack(str(abba)) if connection.out_buffer != "": sent = sock.send(connection.out_buffer) if sent != len(connection.out_buffer): connection.out_buffer = connections[sock.fileno()].out_buffer[sent:] else: connections[sock.fileno()].out_buffer = "" for sock in error_list: print "fel på %s" % sock.fileno() # logics for fileno, connection in connections.iteritems(): if time.time()-connection.timestamp > connection.pingtime: connection.timestamp = time.time()