@Override
    public void put(String key, String value) throws KVException {
        if (key == null || key.length() == 0)
        	throw new KVException(KVConstants.ERROR_INVALID_KEY);
        if (value == null || value.length() == 0)
        	throw new KVException(KVConstants.ERROR_INVALID_VALUE);
        
        KVMessage kvm = new KVMessage(KVConstants.PUT_REQ);
    	kvm.setKey(key);
    	kvm.setValue(value);
    	
    	Socket sock = null;
        try {
        	sock = connectHost();
        	kvm.sendMessage(sock);
        	
        	KVMessage receive = new KVMessage(sock);
        	if (!receive.getMessage().equals(KVConstants.SUCCESS))
        		throw new KVException(receive.getMessage());
        }
        catch (KVException ex) {
        	throw ex;
        }
        finally {
        	if (sock != null)
        		closeHost(sock);
        }
    }