Esempio n. 1
0
 def receive(self):
     while self.connected:
         try:
             #print "ska recva"
             read = self.s.recv(1024)
             #print "har recvat %s" % read
             if read != "":
                 self.in_buffer += read
                 can_split = buffrify.split_buffer(self.in_buffer)
                 if can_split is not None:
                     #print " är inte none."
                     self.in_buffer = can_split[1]
                     pack = Packet.from_str(can_split[0])
                     print "> %s, %s" % (pack.type, str(pack.data))
                     if pack.type in network_listeners:
                         network_listeners[pack.type](pack)
                     else:
                         logging.warn("qos fick ett paket den inte vet vad den ska göra med: %s" % pack.type)
             else:
                 self.connected = False
                 print "fick en tom read i client"
                 break
         except KeyboardInterrupt:
             self.KeyboardInterrupt = True
             print "fick interrupt i receive"
             self.connected = False
Esempio n. 2
0
 def receive(self):
     while self.connected:
         try:
             read = self.s.recv(1024)
             if read != "":
                 self.in_buffer += read
                 can_split = buffrify.split_buffer(self.in_buffer)
                 if can_split is not None:
                     self.in_buffer = can_split[1]
                     pack = Packet.from_str(can_split[0])
                     print "> %s, %s" % (pack.type, str(pack.data))
                     if pack.type in network_listeners:
                         network_listeners[pack.type](pack)
             else:
                 self.connected = False
                 print "fick en tom read i client"
                 break
         except KeyboardInterrupt:
             self.KeyboardInterrupt = True
             print "fick interrupt i receive"
             self.connected = False
Esempio n. 3
0
        read_list, write_list, error_list = select.select(
            client_sockets.values(),
            client_sockets.values(),
            client_sockets.values(), 0)

        to_be_removed = []
 
        for sock in read_list:
            # TODO: fixa in_buffern :p
            # och in_queue
            connection = connections[sock.fileno()]
            #print "läsa från %s" % sock.fileno()
            read = sock.recv(1024)
            if read != "":
                connection.in_buffer += read
                can_split = buffrify.split_buffer(connection.in_buffer)
                if can_split is not None:
                    connection.in_buffer = can_split[1]
                    read = can_split[0]
                    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 \