Hi guys, I'm doing some network programming on the school Linux computers, and I need some help with sockets. Essentially, I have two programs: one that will scan for an open port, and one that will connect to the open port the other one found. My problem is that if I open a socket on a port and find out it's open, even after I close it, the other program can't listen on that port because it hasn't finished it's linger time. And for the second program that does the connecting, I'm using the Thrift network, so I have no control over HOW it connects to the socket. I just give a port number and that's it.

So I'm really stuck here. In C/C++, how can I go about finding an open port on my machine, yet still be able to connect to that port from another program? Any help would be much appreciated.

Thanks in advance.