Some commanders have more a knack for it than others. Commanders also have help from their intelligence specialists, Special Forces and psychological warfare officers, who advise on who is important (and why), and what issues are best raised, or avoided. One important bit of planning is the guest list itself. It usually does not pay to invite people who are feuding with each other, or someone who is of too high, or low, a stature to fit in with the other guests.
Even in Sunni Arab areas, which are full of people that are anti-American (and pro-Saddam or al Qaeda), it is usually possible to hold a diwaniya. Arabs understand that these meetings are meant to try and reach some common ground, and improve the situation for everyone. Commanders also have to deal with frank talk, and be polite in the face of an anti-American diatribe, or widely believed legends (like the one about Israeli commandoes actually being responsible for the 911 attacks, or that Saddam was a good guy who is simply misunderstood by Americans). While Arabs tend to find a diwaniya relaxing and refreshing, these meetings can be an ordeal for the American host. Many Iraqis still entertain fantasies that Americans can do anything, and feel offended if some impossible request is turned down. But the diwaniyas have proved to be very useful. Aside from the obvious opening of communications with locals, the meetings also provide a relaxed way makes deals and gain allies.
One of the more useful tools in fighting Islamic terrorism is an ancient Middle Eastern custom that has been adopted by American commanders. It's called the diwaniya, and it's basically a regularly scheduled "open house" where some local big shot hosts local friends, supporters and those looking for a favor. In practical terms, a diwaniya is a bunch of guys sitting around at night, drinking coffee, snacking and talking things over. In Iraq, the commanders of units (division, brigade, battalion) that have resources to share with locals (reconstruction funds, or the "mad money" given to support combat operations) call together local notables (politicians, tribal and religious leaders, businessmen) for a chat. Everyone knows the commander has money, and other favors, to dispense, and deal making is in the air. The only drawback for Americans is that all this has to be done in slow motion. Arabs like to chat a bit before getting down to business.