Is TCP port in use? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- SymbolicFrank · 2017-07-25 11:10 How do i find that out? I can find an example that parses netstat, and another one that uses winsock. I would like a multi-platform solution, so i tried creating a Synapse TTCPBlockSocket, bind it to the port and listen to it. But it seems that it happily lets me bind multiple sockets to the same port. It's hard to find out if an error did occur. So, I have no idea how to do that. Well, I'm pretty sure I did that some years ago, but I forgot how I did it. ---------------------------------------------------------------------- tudi_x · 2017-07-25 11:31 hi, you can check as a starting point for listening on a socket only the code in: http://forum.lazarus.freepascal.org/index.php/topic,37657.0.html ---------------------------------------------------------------------- Thaddy · 2017-07-25 12:43 The port is in use if a connection is refused as per the documentation....  The TCP/IP documentation that is........ The protocol, not pascal.... So check connection, don't ASSUME it can be made. How can you find it out? Try to connect, don't assume to connect.... ---------------------------------------------------------------------- SymbolicFrank · 2017-07-25 13:19 Well, both Windows and Linux have a netstat command that shows the status. I could make a function that parses the output of both, but that seems a very inelegant and roundabout way to figure it out. ---------------------------------------------------------------------- SymbolicFrank · 2017-07-25 14:06 Ok Thaddy, I changed it in trying to connect to that port. That works. ---------------------------------------------------------------------- Remy Lebeau · 2017-07-26 19:11 Quote from: SymbolicFrank on July 25, 2017, 01:10:20 pmHow do i find that out? The only way is to either: 1. actually attempt to make a connection to it and check if it succeeds or fails. 2. use platform-specific APIs to enumerate ports in use (Get(Tcp|Udp)Table/2(), Get(Tcp|Udp)6Table/2(), and GetExtendedTcpTable() on Windows.  "/proc/net/tcp" and "/proc/net/udp" on Linux.  etc).