4

I am working on an application that uses AsyncSocket .

Is there a way to check if a specific port is being blocked by a firewall?

User97693321
  • 3,336
  • 7
  • 45
  • 69
Jorge
  • 2,056
  • 1
  • 16
  • 23

1 Answers1

0

Usually you won't be able to know if the port is blocked unless you try to communicate from that port and get a response, as far as I know at least. You can determine if that port is in use however. This method is used in GCDAsyncSocket to determine such a case.

NSError *error = nil;

    if (![socket bindToPort:port error:&error])
    {
        [self logError:[NSString stringWithFormat:@"Error binding port: %@", error)]];
        return;
    }

Networking is very much a hit and hope approach a lot of the time.

aronspring
  • 276
  • 2
  • 11