How do the two work together? I've been told that generally when you write a song, to go about it in the traditional fashion, would be to select a key first, and then the key determines which chords are available, and the melody comes from the scale tones of the given key. How does one know how to use a specific chord progression to support a specfic melody? or vice versa? What I mean in nutshell is, how does harmony function in terms of supporting a melody? Are there any basic rules that apply, or one should abide by?
Got a few years? What you're asking is basically, "How do you make music?" That's not something that can be answered on Talkbass. Maybe if you went through every thread on here and took notes, you might figure out a little bit, but the best way is to learn theory and listen to songs you like. Listen close to how the melody and chord changes interact in the songs you like, and try to emulate it.
People spend their entire lives searching for the answers to your questions. In order to truly study the art of songwriting I'd recommend some solid reading and formal teaching in theory, and while you're doing that, just start plunking away and writing songs, good, bad, or mediocre. Practice makes perfect with songwriting, as well as playing.