Well, it's important to remember that Kennedy and Nixon weren't all that ideologically different from each other, at least in the late 40s and early 50s. Both men were centrists and pragmatists at heart, both men were hawkish internationalists, both men were fiscal moderates. Although they had very different childhoods, they still came from the same generation, meaning they had certain parts of their outlook on the world in common. It's important to remember here that the 1950s probably was the time in US history where the two major parties were the closest they would ever get to each other. The mainstream Republican Party had accepted the New Deal, the mainstream Democrats had accepted anti-Communism. It was the general zeitgeist of needing new, younger leaders for the post-WWII Pax Americana. Both men were still definitively liberal and conservative, respectively, as seen by their exchange by the Taft Hartley Bill. But I don't think it affected their politics all that much-I don't think these things would have been changed if they never met.
The men met and established a rapport on a train in 1947 as buck Congressmen. Both were on the same committee (Education and Labor) and were tapped to debate the Taft-Hartley Bill with each other-the first Kennedy-Nixon debate. On the overnight train back to Washington, the two spent time exchanging their views on foreign policy. Later on, when Kennedy was a Senator and Nixon was VP(thus President of the Senate), the two would have offices close to each other. I'm not sure if they were "best buddies"-after all, they did belong to rival parties and had very different personalities-but JFK thought enough of Nixon to invite him to his wedding to Jackie, and Nixon could barely hold back tears when Kennedy was in serious trouble after his back surgery in 1954. It was truly something to see the two exchange friendly notes and book recommendations, knowing what would happen in 1960. I'd recommend looking at their fellow colleague of the "class of '47", George Smathers' recollections, he had a pretty trusting relationship with both men.