Using winsock, how can I tell if a system is listening for a connection on a port before I call connect?
-
I've got an application that runs on several computers which handles simultaneous video capture (to be clear, each system runs it's own copy of the capture software). I've got another application that runs on another computer and is used to control capture software that is running on the other systems. Currently, the capture software uses the winsock call "listen" to listen for incoming connections on a specific port. When I want to connect to the capture systems from the control system, I use the winsock call "connect" to make the connection. Currently, I cycle through a list of possible capture machines and attempt to connect to each one, however, the capture systems may or may not be running the capture software. Because connect doesn't allow me to specify a timeout, this connection process can take an extremely long time if even a single capture system is powered down or isn't running the software. So my question is: Is there a way to check to see if a system is listening for a connection before I call connect? Or, is there a better way to handle establishing connections between my machines. Thanks, Adam Kraver
-
I've got an application that runs on several computers which handles simultaneous video capture (to be clear, each system runs it's own copy of the capture software). I've got another application that runs on another computer and is used to control capture software that is running on the other systems. Currently, the capture software uses the winsock call "listen" to listen for incoming connections on a specific port. When I want to connect to the capture systems from the control system, I use the winsock call "connect" to make the connection. Currently, I cycle through a list of possible capture machines and attempt to connect to each one, however, the capture systems may or may not be running the capture software. Because connect doesn't allow me to specify a timeout, this connection process can take an extremely long time if even a single capture system is powered down or isn't running the software. So my question is: Is there a way to check to see if a system is listening for a connection before I call connect? Or, is there a better way to handle establishing connections between my machines. Thanks, Adam Kraver
Unfortunately you can't find out if a TCP port is open other than trying it. However there some design you could give a try: - time out the connect call or use a socket library that can - use a separate protocol to check availability, this could be the control system actively checking the hosts or the hosts sending an "hey I am alive" message in regular intervals - use more than one client on the control system to compensate for delays Hope it helps /M