All pastes #518987 Raw Edit

Untitled

public text v1 · immutable
#518987 ·published 2007-05-29 14:27 UTC
rendered paste body
    def sendPacket(self, packet):
        try:
            sock = socket(AF_INET, SOCK_DGRAM)
            sock.settimeout(0.25) # who knows if 250ms is enough
            start = time()
            sock.sendto(packet, (self.server, int(self.port)))
            while 1:
                try:
                    data, addr = sock.recvfrom(self.buffer)
                except: #if timeout
                    self.dead = bool(1)
                    return None
                stop = time()
                sock.close()
                self.ping = int((stop - start) * 1000)
                return data
        except TypeError:
            self.dead = bool(1)
            return None
        except error:
            self.dead = bool(1)
            return None