@Override
    protected Void doInBackground() throws Exception {
        Client loginClient = new Client(4096 * 2, 4096 * 2);

        loginClient.getKryo().register(PacketLogin.class);
        loginClient.getKryo().register(PacketLoginResponse.class);
        loginClient.getKryo().register(PacketRequestCaptcha.class);
        loginClient.getKryo().register(PacketCaptchaImage.class);
        loginClient.getKryo().register(byte[].class);
        loginClient.getKryo().register(PacketRegister.class);
        loginClient.getKryo().register(PacketRegistered.class);
        
        loginClient.addListener(new Listener() {
            @Override
            public void received(Connection connection, Object object) {
                if (object instanceof PacketCaptchaImage) {
                    PacketCaptchaImage response = (PacketCaptchaImage) object;
                    System.out.println("Invalid captcha, new: " + response.toString());
                    
                    publish(new RegistrationState(response));
                    
                    connection.close();
                } else if (object instanceof PacketRegistered) {
                    PacketRegistered response = (PacketRegistered) object;
                    System.out.println("Registered: " + response.toString());
                    
                    publish(new RegistrationState(true));
                    
                    connection.close();                    
                }
            }
        });

        loginClient.start();

        try {
            loginClient.connect(5000, Constants.SERVER_HOST, Constants.SERVER_PORT);   
            
            PacketRegister pr = new PacketRegister();
            pr.username = login;
            pr.password = password;
            pr.captchaKey = key;
            pr.captchaAnswer = ans;
            
            loginClient.sendTCP(pr);
        } catch (Exception e) {
            e.printStackTrace();
            
            return null;
        }
                      
        return null;
    }