Currently, I’m working on TCP client/server implementation in C. In that, I found that I can give any random number as a port number for my PC. Is it correct procedure? Or is there any standard port number for my PC?
Currently, I’m working on TCP client/server implementation in C. In that, I found that
Share
I don’t know the standard, but I say it’s not. At least, I don’t like to do it like that.
You can check occupied ports by parsing the outputs of programs like
netstatand avoid using those. You can also use the method that attempts connecting on one port, and upon failure, tries another port. Unless you’re really really unlucky, you should get a valid port on second try.You should use ports within the ranges of 49152–65535. Ports below 49152 are reserved/registered.