What is a port?
An application "listens" on a port to recieve a connection from an application on another computer.
How do you know if a port is open? (listening)
Well, typically, by trying to connect. So these scanners will try to connect to every port that you want, and it will tell you if it succeeded (open) or failed (closed).
Once you know what ports is open, you can guess or figure out what programs opened that port. If you figure out what program opened it, you may then start communicating with that program and tell it what to do.