iOS SDK: How can I check if a port is open?

后端 未结 1 1921
北海茫月
北海茫月 2021-01-19 14:11

I have not found anything yet on how to check if a port is open or not. I tried to realize it with the AsyncSocket class but it returns always TRUE although I reject all con

相关标签:
1条回答
  • 2021-01-19 14:44

    You need to make yourself the delegate and handle the onSocket:willDisconnectWithError: method. The connection is entirely async so unless there is a fundamental system problem (sockets are disabled, you passed in an invalid address, etc) then that call will always succeed while the socket connection attempt happens in the background.

    If that attempt fails, the onSocket:willDisconnectWithError: delegate method will get called so you can know the connection attempt failed.

    I'm not sure why but the AsyncSocket class considers the kCFStreamStatusError stream status to be "connected" so I suspect that is why it shows up as connected. You can follow all this in the source of AsyncSocket.

    0 讨论(0)
提交回复
热议问题