Translation:May I come in?
That's right, but from my experience, a lot of speakers of other pure Bantu languages don't consider Swahili pure because of the heavy borrowings from Arabic dialects. It's comparable to saying that English is a Germanic language, but highly altered due to the influence from French and Latin.
It is spoken loudly to ask for permission to enter - it is used instead of knocking (as we do in our/many/other cultures) - and the speaker should/would wait for "Karibu" (welcome) before entering - if nobody answers, the "hodi" calls may go on for quite a while before they assume no one is at home and return/leave.
"Hodi" reflects a culture where some people had doors and some didn't. To call out "hodi" meant "hi anyone in?", and you never entered until you received a "karibu" (welcome). This ensured privacy and recognition of property, even if there was no door or gate. So these direct translations are somewhat limiting as they come from a different cultural perspective. I think it should accept "may I come in?", "knock" or "anyone in?"
Here in Tanzania you do not use it when asked to come in. you say hodi then the person inside will say karibu(welcome) or subiri kidogo(wait a little bit). Once you enter inside you start the regular greetings. At least that is my experience here in Tanzania. But it is not uncommon to say more than once. I will usually say it outside a person's gate and again right outside the person's home.