I need to be able to check if a communication given port is available. What is the best way to do it?

Thanks for your help!