1 Reply
      Latest reply on Feb 24, 2017 2:25 PM by eskimo
      Smotyn Level 1 Level 1 (0 points)



        So I have a service hosted in a data centre, that requires a number of TCP ports to be available on the client device network.

        I would love to be able to have the my app check whether the ports are open or not before booting up - i.e. are they being blocked by a web filter/firewall etc?

        Research so far has lead me to CFStreamCreatePairWithSocketToHost which is working extremely well, as I can connect to the IP/ports in sequence and report back as to which ones are open.

        The limitation is that it only allows you to add one IP address in, whereas ideally I would like to provide it with a range.

        Can I ask if anyone knows if CFStreamCreatePairWithSocketToHost can scan across an IP range? Am I looking in the wrong place? Any help/support/suggestions would be really greatly appreciated. Many thanks!

        • Re: tcp port checking with CFStreamCreatePairWithSocketToHost
          eskimo Apple Staff Apple Staff (13,915 points)

          Can I ask if anyone knows if CFStreamCreatePairWithSocketToHost can scan across an IP range?

          Under the covers socket stream simply opens a TCP connection to the DNS name (or IP address) and port you specify.  That’s good, in that it’s the only guaranteed way to determine if the device can, at this instant, connect to that DNS name and port.  However, there’s no way to open TCP connections to a range of IP addresses; that simply does not make sense at the TCP level.

          You can, however, do this stuff in parallel, that is, open 10 socket streams to the 10 different DNS name and port pairs.

          However, this sounds like preflighting to me, and that’s rarely a good idea.  The fact that you were able to open a connection a few minutes ago is no guarantee that you can open a connection now.  In most cases you want to avoid preflighting, and instead do the network operations you need to do when you need to do them, and deal with any errors you encounter.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

          1 of 1 people found this helpful