I have run across multiple ways to check and see if a port is in use and the quickest and easist way is to run a the following netstat command. For example: if you wanted to see if port 9800 was currently in use, you would enter
netstat -an | grep 9800
Returns the following if port 9800 is already in use, in this case, an application is already listening on port 9800:
$ netstat -an | grep 9800
*.9800 *.* 0 0 49152 0 LISTEN
If the port was not in use, the following would get returned:
netstat -an | grep 9801
$