A common theme we see in the Odyssey is travelers being showered with hospitality, gifts and a warm bed when asking a stranger for a place to spend the night. How prevalent was this practice really? If I was traveling could I really expect any stranger to offer me a meal and a place to stay by simply knocking on their door? Were there limitations on this hospitality? Say a sketchy looking stranger came to my house looking for a place to stay… Would cultural tradition force me to take him in, even if I thought there was a risk?
The society portrayed in the Odyssey is not one that's contemporary with the composition of the poem, in most respects: from the poet's perspective, Odysseus and his journeys belong to the distant past, and so naturally the society depicted is a fictionalised reimagining of that distant past. This is why, for example, iron is portrayed as a precious metal (even though it's used for some everyday objects), why numerical expressions of value are specified as a number of oxen (a practice that probably wasn't in use after the 8th century at the latest), and why the landscape of Odysseus' travels is mostly empty of human societies.
Odysseus himself is effectively cast as a precursor and archetype for the colonists of the time: in reality, at the time of the poem's composition there were Greek colonies spreading all over the west, southern Italy was already effectively part of the Greek cultural domain, and trade contacts with the Etruscans to the north were very strong. So Odysseus is a fictionalised combination of proto-colonist (explorer) and proto-trader (he's the best there is at obtaining wealth via travel; he's the man who can walk into any town without a scrap of clothing on his back, and walk out piled with gifts).
So the same goes for xeiniē (that's the Homeric form of xenia): on one hand it's (presumably) a genuine attempt to recapture how folks thought things worked in the distant past, but on the other hands it's also an attempt to paint a sort of proto-xenia, the precursor and archetype of real-life xenia, in the same way that Odysseus is an archetype for contemporary colonists. That doesn't necessarily mean the Homeric picture of xeiniē is pure fabrication: many ancient historians interpret Homeric society as a real historical society. But it is important to realise that everything is filtered through multiple layers of (a) what the poet believed about the past, and (b) what kind of just-so story the poet wanted to tell about the present.
Xenia in the historical period took two forms. The first was much more professionalised than the personal friendships you see in the Odyssey. From a very early date, it was customary for a person from city A to live in city B and act as city A's proxenos: an ambassador of sorts. These proxenoi were extremely important both to city A and city B. Here's one particularly famous tomb of the Oianthean proxenos on Corfu, a man named Menekrates: an inscription records how the Corfiotes erected a monument to him at their own public expense, and how his death was seen as a public disaster. Proxenoi were very important members of the community. This was in the late 7th century (Menekrates' tomb is in fact the earliest evidence of proxenia). So this is how people who lived a generation or two after the Odyssey handled the problems of travel: you wouldn't go and knock on some random person's door, you'd go straight to the proxenos and he'd set you up with someone. There may be a trace of this in the Odyssey in book 15 when Telemachos brings Theoklymenos to Ithaca and, rather than putting him up in his own house, tells Theoklymenos that he'll arrange accommodation with someone else in the town.
The second form was a religious rite called Xenia or Theoxenia in which people would lay out tables of food for visiting gods or spirits of heroes, as part of a communal feast. This form sounds a lot more like the very formalised hospitality scenes that we see in the Odyssey, with set-piece scenes and formulae revolving around the appropriate way to welcome a guest. The big difference, of course, is that in Theoxenia you're not doing this for an actual corporeal person. However, there is a close link in the Homeric Hymn to Demeter, which depicts a theoxeny (i.e. visitation by a god) of this kind, but uses the same set-piece elements that we see in the Odyssey. You can say that some hospitality scenes in the Odyssey are also secretly theoxenies, if the guest is Athena in disguise.
But Homeric xeiniē as practised between mortals isn't quite like either of these. It's not impossible that a real historical practice underlies the hospitality shown in the poem: hospitality, and the civilised behaviour expected of both host and guest, is a central theme of the poem, since the Suitors' main crime lies in betraying the "rules" of hospitality. But the historical practices we have attested elsewhere are so different from Homeric hospitality that it's reasonable to put the burden of proof on someone who wants to show it is a historical practice. To my mind, Homeric hospitality is more of a symbolic hook to hang all sorts of ideas on: civilisation vs. barbarism, good vs. evil, exploration and colonisation, trade. Exploration and colonisation I touched on earlier. Civilisation vs. barbarism: xeiniē is what sets Odysseus apart from the Suitors, and what separates civilised Greeks from the monstrous Cyclops, who gets all the rules of xeiniē wrong. Trade: xeiniē is also the tool that Odysseus uses to accumulate wealth (19.282-6: "Odysseus would have got home a long time ago, but he wanted to travel the earth and gather wealth; he knows more than anyone else about great profits"). So to me it looks more likely to be a formula originally from a ritual context, which has been coopted to tell a story about the time when the visiting heroes were still alive.
I'd also suggest looking at the xenia moment in Book 6 of the Illiad, which almost borders on comedy to describe, as Glaucon and Diomedes run into each other on the battlefield, say "hey, I haven't seen you around this war before, who are you," recite lineage, realize their families make them xenia, and agree not to kill one another but to trade goods. Likewise, in the Odyssey, it's gift exchange that goes on in Book 15 with Menelaus, and in Book 1 you have Athena-as-Mentes as xenia enjoying guest-privilege on an outright trade mission, but in that context of "your granddad and I, we go back," as well as the comment in Book 19 that rosemary85 discussed. So, maybe, we have some shadowy representations of commercial culture or economic structure that had a more gift-based logic to it, where it's not just about strangers in general but preferred trading partners with whom you have and offer credit (in an honorable way), with some sense of how it's considered noble to be that guy who's first willing to risk the first transfer.