'This is the main loop of the process when in \'external\' mode.'

def main(self):

    self.interrupted = False
    backlog = 5
    size = 8192
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.connect((self.host, self.port))
    input = [server]
    databuffer = {}
    IVs = {}
    init = server.recv(size)
    print 'got    init', init
    (iv, t) = struct.unpack('!128sI', init)
    print 'IV', iv
    print 'T', t
    version = 0
    pad1 = 0
    crc32 = 0
    timestamp = int(time.time())
    rc = 2
    hostname_dirty = 'moncul'
    service_dirty = 'fonctionnne'
    output_dirty = 'blablalba'
    pad2 = 0
    '\n                                Read    the    check    result\n                                    00-01:    Version\n                                    02-05:    CRC32\n                                    06-09:    Timestamp\n                                    10-11:    Return    code\n                                    12-75:    hostname\n                                    76-203:    service\n                                    204-715:    output    of    the    plugin\n                                    716-720:    padding\n                                '
    init_packet = struct.pack('!hhIIh64s128s512sh', version, pad1, crc32, timestamp, rc, hostname_dirty, service_dirty, output_dirty, pad2)
    print 'Create    packent    len', len(init_packet)
    data = decrypt_xor(init_packet, iv)
    data = decrypt_xor(data, self.password)
    server.send(data)
    raise SystemExit(0)
    while (not self.interrupted):
        print 'Loop'
        (inputready, outputready, exceptready) = select.select(input, [], [], 1)
        for s in inputready:
            if (s == server):
                iv = self.send_init_packet(client)
                IVs[client] = iv
                input.append(client)
            else:
                data = s.recv(size)
                if (s in databuffer):
                    databuffer[s] += data
                else:
                    databuffer[s] = data
                if (len(databuffer[s]) == 720):
                    (timestamp, rc, hostname, service, output) = self.read_check_result(databuffer[s], IVs[s])
                    del databuffer[s]
                    del IVs[s]
                    self.post_command(timestamp, rc, hostname, service, output)
                    try:
                        s.shutdown(2)
                    except Exception as exp:
                        print exp
                    s.close()
                    input.remove(s)
