Most MIDI devices have a third port "MIDI thru", and the input is passed directly to this port so you can chain devices. Sometimes the output port doubles as thru. For more complicated setups there are midi patchers/mixers available. There's one downside to this: if you chain too many devices you might run into latency problems.