Can I let my friend come and join me in my hotel room, just for visiting? Not sleeping or eating.
IMHO the answer to your question will inevitably depend on the country, the hotel, or a combination of both.
Generally speaking, my experience shows that you can indeed visit people staying in hotels. I've had friends and family come pick me up when I was staying in hotels, and I've also been the visiting one. What usually happens is that the person walks up to the reception and asks to see Mr. Doe in room 666. The reception then calls room 666 and asks the hotel guest what to do with their visitor. It is likely that reception staff will register the person before they are let up to the room. This is assuming that the visit is of short duration. However, your mileage may vary if you are thinking of having a guest over for a couple hours, and then have them leave.
Just as an example, a random google search shows that some hotel mention unregistered guests in their Terms and Conditions, allowing them to stay during day-hours (10:00 to 20:00):
Unregistered Extra Guest
Visitors of guests are allowed on the Hotel’s premises daily between 10am and 8pm. The guest is to adhere to these visiting hours and escort their visitors at all times on the hotel’s premises.
Unregistered extra guest. No more than 2 adults are allowed to stay at any room/suite at Hotel Troiz. All guests are required to register on arrival at the hotel. Registered guests are prohibited from allowing non-registered guests from staying in their rooms beyond 8pm. Any additional unregistered guest found in a guest room between 8pm and 10am will incur a penalty charge of 100 Euros per person. Such fees will be added to the relevant registered guest account, for payment prior to departure.
This discussion on FlyerTalk seems to point to the fact that such a regulation might be commonplace among several establishments.