listen for output and open/close port logic