public void registerWithMaster(String masterHostname, SocketServer server)
            throws KVException {
        String regInfo = slaveID + "@" + server.getHostname() + ":" + server.getPort();
        KVMessage reg = new KVMessage(KVConstants.REGISTER , regInfo);
        Socket sock = null;
        
        try {
        	sock = new Socket(masterHostname , 9090);
        }
        catch (IOException ex) {
    		throw new KVException(KVConstants.ERROR_COULD_NOT_CONNECT);
    	}
    	catch (Exception ex) {
    		throw new KVException(KVConstants.ERROR_COULD_NOT_CREATE_SOCKET);
    	}
        
        try {
        	reg.sendMessage(sock);
        	KVMessage resp = new KVMessage(sock);
        	if (!resp.getMsgType().equals(KVConstants.RESP) ||
        		!resp.getMessage().equals("Successfully registered " + regInfo))
        		throw new KVException(KVConstants.ERROR_INVALID_FORMAT);
        }
        catch (Exception ex) {
        	throw new KVException(KVConstants.ERROR_INVALID_FORMAT);
        }
        finally {
        	try {
        		if (sock != null)
        			sock.close();
        	}
        	catch (Exception ex) {        		
        	}
        }
    }